I have a small application I created to analyze the network connection. It runs from a browser and connects to a local PHP/Apache server. It then asks PHP to send a ping packet through a raw socket. THe problem is that if the host I am trying to ping isn't alive or won't answer to pings, we never get an answer from the server.
I beleave the socket request lives until apache is restarted. I have been getting mixed results from my application lately and I am blaming apache using too many sockets. Currently I have set the AJAX call's timeout and I was happy with it. But I really need to make PHP do the timeouting so that I won't have 500,000 sockets open to an unreachable host.
Some sample code:
$sockconn = @socket_connect($socket, $target, null);
if(!$sockconn)
{
$raw['error'] = socket_strerror(socket_last_error());
$raw['status'] = false;
return $raw;
}
This is the function that won't timeout. I need to get it to timeout. Also PHP script execution time DOES NOT affect sockets.
I am clueless.
fsockopen()instead. It makes a lot of things a lot easier, it is more readily available (it is a core function that must be explicitly disabled, whereas the sockets extension must be explicitly enabled) and the 5th argument lets you define the connect timeout on a per-call basis.stream_socket_*functions rather thanfsockopen()). In practice it would be a massive PITA. I sort of assumed you would be dealing with TCP, most of the time that's what people are doing. If what you want is a PHP-driven ICMP echo implementation, though, I've already done that... take a look at this: download.networkm.net/code/php/class.ping.1.0.tar.gz (note that it was written for PHP4, and when my OO skills left... something to be desired, but it does work I have used it a couple of times)