php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16114 fputs doesn't send all data(WORKS!)
Submitted: 2002-03-16 15:16 UTC Modified: 2002-12-01 19:47 UTC
From: manu at chasqui dot uclv dot edu dot cu Assigned:
Status: Closed Package: Sockets related
PHP Version: 4.1.1-4.3/CVS OS: Windows 2000 AS
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: manu at chasqui dot uclv dot edu dot cu
New email:
PHP Version: OS:

 

 [2002-03-16 15:16 UTC] manu at chasqui dot uclv dot edu dot cu
A few months ago, I was doing transfers using socket functions, it all worked fine(php 4.0.4 or php 4.0.5).
I code something like this:

  $p = fsockopen( $url, $port );
  if (!$p) die('Cannot connect');
  $l = fputs( $p, $data );
  fclose( $p );

With this I sent up to 5MBs to a server. Now, the web server's administrator has upgrade to 4.1.1. The php.ini file has:
  post_max_size=10M
  upload_max_filesize=5M

The fact is that it works but doesn't sending large streams. I make a test with a string of 100Kb of text, and the server received only 8Kb(and sometimes less).
I inserted a dead loop before fclose and still the server got the client disconnection before de php_max_execution_time elapsed.
The same thing happens in php 4.0.6.

Manu.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-03-16 20:39 UTC] wez@php.net
Have you tried fflush($p) before you fclose()?

 [2002-03-25 13:16 UTC] manu at chasqui dot uclv dot edu dot cu
I did once I received your reply. It didn't work either.

Manu.
 [2002-03-25 14:14 UTC] wez@php.net
Could you try sending the data in smaller chunks that are
< 8KB each?

I think I might have a solution.
--Wez.
 [2002-03-25 15:42 UTC] manu at chasqui dot uclv dot edu dot cu
I did something like this. Didn't work.

  $socket = fsockopen( $host, $port, $err1, $err2, 30 );
  if (!$socket) die ('conn');
  $start = 0;
  $len = 4*1024;
  $result = 0;
  while ($result < strlen($request))
  {
    $chunk = substr( $request, $start, $start+$len );
    $result = $result + fputs( $socket, $chunk );
    fflush( $socket );
    $start = $start+$len;
  }
  fclose( $socket );

Hope you find the answer. :->
Manu.
 [2002-03-25 16:12 UTC] manu at chasqui dot uclv dot edu dot cu
I did also a test(without chunking the data), I could send 48653 bytes, but couldn't 49229 bytes. 
With the chunking feature it must be some bug in my code, cause didn't work with 48653 bytes.

Manu.
 [2002-07-10 12:29 UTC] jason@php.net
Could you try this on 4.2.1, and the latest snapshot on http://snaps.php.net/win32/ ?

The internal streams subsystem has been implemented in the snapshots, which is a complete rewrite.

Thanks,

-Jason

 [2002-07-18 21:49 UTC] manu at chasqui dot uclv dot edu dot cu
I will do. In this moment I've been facing troubles with my Internet connection, and I cannot download the snapshots.

Manu.
 [2002-07-21 12:42 UTC] manu at chasqui dot uclv dot edu dot cu
I downloaded the file php4-win32-200207182200.zip and made a test uploading a 3.2MB file. It didn't work. With smallers files(a test with a 13b one) works. I'll do a test trying to establish the failure boundaries.

Manu.
 [2002-09-26 10:38 UTC] wez@php.net
What's the status on this?
Are you sure this is an issue with fputs and not instead
an issue with file upload to a PHP script?
What are you connecting to?
If you are testing again, please try the latest snapshot;
more changes have been made.
http://snaps.php.net/win32/
 [2002-10-13 15:08 UTC] manu at chasqui dot uclv dot edu dot cu
The lastest snapshot(Oct 13, 2002; php4-win32-latest.zip) works almost fine.

This code:
  $socket = @fsockopen( 'localhost', 80, $err1, $err2 );
  if (!$socket) die('socket not open');
  $result = fputs( $socket, $request ); #$request holds a well formed MIME request for posting a file.
  fflush( $socket );
  //echo "<pre>>>\r\n".str_replace('</pre>', '&lt;/pre>', $request)."<<\r\n</pre>";
  fclose( $socket );

This works if the file being posted is small(can't say how much). The point is that if I uncomment the echo line before fclose(), it sends all the data(up to 10.5M=11,076,608 bytes I sent), but without the echo line, it seems that fclose() executes in such a way that chops the socket's output stream and the Web Server does not executes the receive.php script. 
The echo line may be replace by sleep(8) and still working.

Summary:
  Give it time before fclose() a works; otherwise, unstable.

Manu.
 [2002-10-13 18:34 UTC] wez@php.net
I've just committed a little patch that might fix this problem; PHP was calling shutdown(2) prior to closing the socket, and this may have been causing the data-loss.
If you can compile PHP yourself, comment out the shutdown line in main/network.c.
Otherwise, you need to wait for the next snapshot to be built (could be 3 hours away).

Please let me know how you get on.
 [2002-10-13 18:40 UTC] wez@php.net
Scratch that; I just discovered something in the MSDN docs.
 [2002-10-13 18:54 UTC] wez@php.net
Please try the next snapshot.
 [2002-10-29 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over 2 weeks, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2002-12-01 19:47 UTC] manu at chasqui dot uclv dot edu dot cu
Congratulations!

I have done the same tests, and I have sent up to 40MB.
The snapshot I used for testing was: php4-win32-STABLE-200212011730.zip

Manu.
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Fri Jul 01 09:03:48 2022 UTC