Answer the question
In order to leave comments, you need to log in
How to overcome visitor session hangup when pinging using PHP?
PHP script. Apache. Server OS - various (see below)
Ping a specific address using exec
For example:
exec("ping 192.168.0.1 -n 1 -w 350", $output, $status);
If the IP is active, then a completely normal and fast response comes. If the address is inactive, then a response may come that the timeout has expired (the standard ping response), or the session in the browser may completely freeze (the same resource stops working in other tabs). It helps either - opening another browser, or restarting the web server.
Based on the results of the research, it was found that the probable problem is "exec" - ping it, in the case when the IP does not respond - it may not return a response at all. As a result, exec continues to wait for a response and "does not release" the session.
The problem is "chaotic". On some servers where this script runs, it may appear, but on some it doesn't. In this case, the server OS often does not play a role. Windows, Linux, FreeBSD. Somewhere it works, somewhere it doesn't.
We tried to push the ping script into a separate Ajax frame. Doesn't help, because besides - session is hung up.
"Specific" libraries for ping - not suitable, because. it is required to provide work on different server OS
What are the thoughts - what can be done? Thank you.
Answer the question
In order to leave comments, you need to log in
Directly about the "hanging" of the session - sessions use a blocking admission mechanism. Release the session and it won't block other pages from opening: php.net/manual/en/function.session-write-close.php
Performs a ping to a specific address using execIs the command for different OS the same? As far as I know, the single values of the -w parameter in windows and linux are different (millisecond and second, respectively).
For example:
exec("ping 192.168.0.1 -n 1 -w 350", $output, $status);
What are your thoughts - what can be done?If the command is the same for different operating systems, then I suggest adjusting the timeout value for the linux version.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question