Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fgets timeout method???

Status
Not open for further replies.

BobMCT

IS-IT--Management
Joined
Sep 11, 2000
Messages
756
Location
US
I am converting several perl scripts to php and one of them does i/o to a serial tty port. This works very well if the other system is available. However, if the other system is offline then the process just hangs forever.

In perl this code was embedded within an eval { } block that has an alarm() function. If the alarm timer timesout the eval block is interrupted allows control to come back into the primary script and handled accordingly.

I haven't been able to find a similar feature to accomplish this in php. Can anyone please recommend if and how this might be done in php?

Thanks to all who can help.

Bob
 
could try setting a time limit on the function (
or consider this
echo "Attempting to connect to '$address' on port '$service_port'...";
$result = socket_connect ($socket, $address, $service_port);
if ($result < 0) {
echo &quot;socket_connect() failed.\nReason: ($result) &quot; . socket_strerror($result) . &quot;\n&quot;;
} else {
echo &quot;OK.\n&quot;;
}
from (
Bastien

cat, the other other white meat
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top