php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25828 enormus time get result from fgets via fsocketopen
Submitted: 2003-10-10 16:01 UTC Modified: 2003-10-14 10:19 UTC
From: scouture at novo dot ca Assigned:
Status: Closed Package: Performance problem
PHP Version: 4.3.3 OS: win2000
Private report: No CVE-ID: None
 [2003-10-10 16:01 UTC] scouture at novo dot ca
Description:
------------
I was using php 4.2.2 before updating to 4.3.3.
I have to talk to another application server using socket.
With 4.2.2, i had my response in less than a second but it take me about 60 sec with php 4.3.3



Reproduce code:
---------------
function getFromSocket($message){
  set_time_limit (0);	
	$res = @fsockopen ("192.168.10.5", "3734", $errno, $errstr,30);
	if(!$res)	{						
		exit; //some eror...
	}
	else{	
	fputs($res, $message);   
//samething, reponding server end the response by SCKEND
// while (substr_count($buff, "SCKEND")!= 1) 
   while ($bytes != "0"){      
      $buff .= fgets($res,4096);
      //$array_statusSocket = socket_get_status($res); //for 4.2.2
      $array_statusSocket = stream_get_meta_data($res); 
      $bytes = $array_statusSocket["unread_bytes"];      
    }
    fclose ($res);
	}
	return $buff;
}
function getMicrotime(){
	list($usec, $sec) = explode(" ",microtime());
	return ((float)$usec + (float)$sec);
}
$time_requete = getMicrotime();
$str_resultatSocket = getFromSocket("LOG|novojustice|justicenovo|intranet||SCKEND");
$time_requete2 = getMicrotime();
echo $time_requete2-$time_requete ." time<hr>";
exit;

Expected result:
----------------
have the result more quickly

Actual result:
--------------
took about 60sec..

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-10-10 17:02 UTC] wez@php.net
Does the returned data include a newline?

If not you should be using fread().
OR, you can use stream_select(),
OR you can use stream_set_timeout() to reduce the default
timeout from 60 seconds to something more appropriate to your application.
 [2003-10-10 17:09 UTC] wez@php.net
Also, you really should not use stream_get_meta_data() and the unread_bytes value to drive your scripts.
 [2003-10-14 10:19 UTC] scouture at novo dot ca
I've changed my function using stream_select and fread instead and it works fine.

So was more a coding problem than a bug finaly.

Sorry for your time and thanks for your help
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 05:01:33 2024 UTC