From: donald at designknights dot com
Operating system: SUSE linux 10.1
PHP version: 5.2.4
PHP Bug Type: Network related
Bug description: php hangs when using fgets with a socket
Description:
------------
this is a script to connect to a pop3 server and parse emails.
$connection = fsockopen($popServer, $port, $error ,$string ,$timeout);
$response = fgets($connection, $buffer);
$newLine = "\r\n";
$localhost = "www.designknights.com";
if(empty($connection)) {
echo "Failed to connect: $response";
exit;
}
else {
$logArray['connection'] = "Connected to: $response";
}
echo "sending username<br>";
ob_flush();
flush();
fputs($connection, "USER $username". $newLine);
$response = fgets($connection, $buffer);
$logArray['userresponse'] = "$response";
fputs($connection, "PASS $password". $newLine);
$response = fgets($connection, $buffer);
$logArray['passresponse'] = "$response";
if (substr($response,0,3)!="+OK"){
echo "Mail server said: ".$response;
exit;
}
fputs($connection,"LIST".$newLine);
$msg_array = array();
$response = fgets($connection,$buffer);
$logArray['listresponse'] = "$response";
$messages = explode(" ",$response);
$nummessages = $messages['1'];
echo "number of messages =".$nummessages;
stream_set_blocking($connection,1);
for ($i=1;$i<=$nummessages;$i++){
fputs($connection,"retr ".$i.$newLine,$buffer);
$message = '';
$line = '';
//This loop is where it hangs
while (!feof($connection){
$line = fgets($connection,$buffer);
echo "<br> line = $line";
ob_flush();
flush();
}
$message_blown = explode(":",$message);
echo "<br> message $i = <br>";
print_r($message_blown);
}
echo "return = ".print_r($messages)."<br>";
print_r($logArray);
fclose($connection);
Reproduce code:
---------------
See above
Expected result:
----------------
It should to my understanding put the lines into the var names $message
then explode that message into $message_blown using : as a separator.
Actual result:
--------------
it hangs and the max execution time kills php5 while running the script.
--
Edit bug report at http://bugs.php.net/?id=42497&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=42497&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=42497&r=trysnapshot52
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=42497&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=42497&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=42497&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=42497&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=42497&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=42497&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=42497&r=support
Expected behavior: http://bugs.php.net/fix.php?id=42497&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=42497&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=42497&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=42497&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=42497&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=42497&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=42497&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=42497&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=42497&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=42497&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=42497&r=mysqlcfg