U
U
UserSide2014-11-05 20:12:02
PHP
UserSide, 2014-11-05 20:12:02

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

2 answer(s)
M
Melkij, 2014-11-05
@UserSide

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

T
throughtheether, 2014-11-05
@throughtheether

Performs a ping to a specific address using exec
For example:
exec("ping 192.168.0.1 -n 1 -w 350", $output, $status);
Is 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).
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 question

Ask a Question

731 491 924 answers to any question