re:socket_set_blocking
| From: | Joseph H Blythe | Date: | Wed, 23 Aug 2000 04:11:43 +0000 |
| Subject: | re:socket_set_blocking | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-13075@lists.php.net to get a copy of this message | ||
Hey,
I have been messing with this function, and have tried various things,
it seems to me that something is wrong when socket_set_blocking is set
to false, fgets will fail or any number of strange results will be
received, set it to true and every thing returns to normal.
One thing I would like to know has anyone ever successfully used this
function in conjunction with fgets before?
How would you suggest to test if a fgets command has returned nothing?
If socket_set_blocking is true the script just waits for a response so
if none is received there is no way to time it out. here is an example
of what im trying to do, of course you need something like
http://www.l0pht.com/~weld/netcat/ to simulate a
server app that would
send something back when a request is received.
$fp = fsockopen(some_ip_address_here, some_port_here, &$errno &$errstr,
30)
or die ("Error connecting to remote host.");
$pck = "This is a transaction request";
fputs($fp, $pck) // Send transaction request
or die("Error cannot send data to remote host.");
socket_set_blocking($fp, 0);
while ( !feof($fp) ) {
$buffer = fgets($fp, 1024) // Get transaction response
or die("Error no data recieved from remote host");
}
// Test to see if an response has been received, if not try a number of
times before dying
$status = "This is a status of an transaction request";
$i = 0;
while( empty($buffer) ) {
if ( $i < 2 ) {
sleep(10);
fputs($fp, $status) // Send status request
or die("Error cannot send data to remote host.");
} else {
break;
}
if ( empty($buffer) ) {
$i++;
continue;
} else {
break;
}
}
@fclose($fp)
or die("Error cannot close remote connection");
This gives you the general functionality I am thinking of, but this wont
work as when socket_set_blocking is set to true, script just hangs, set
it to false it will die with the Error cannot recieve data from remote
host.
Please someone I need help on this one!
If any one knows any or is a PHP developer in Adelaide South Australia
could they please let me know?
Regards,
Joseph Blythe
--
BoldFX / Binary Logic
257 Churchill Road Prospect South Australia 5082
Ph: (08) 8342 0022 Fax: (08) 8342 0155
mailto: joseph.blythe@binarylogic.com.au