> As http server is stateless, php can not know if a client has stop requesting. > you should do your trick on the client side. > > But if you insist doing this on the server, you may need to write a daemon > process or crontab job , here's the step > > 1. Everytime the client make a request, your php code write a timestamp in a > temp file. > 2. Your daemon process should read this file and compare to the timestamp > by NOW, if it is larger than you expect ,then do the if statement thing in the > daemon process. Look what I have accomplished in my script, the problem in my script when " session_destroy();" and " unset($_SESSION['timeout']);" happen it supposed to kill "timeout" then "while loop if(time() > $st) " will stop. But theses not happing im wondering why. Can you look in my code and see? <?php session_start(); ?> <?php for( $x=0; $x< 50; $x++ ) { $st = $_SESSION['timeout'] = time() + 10; session_destroy(); unset($_SESSION['timeout']); } $loop= true; while($loop) { if(time() > $st) { file_put_contents('/tmp/phptest1234.txt', 'test'); $loop=false; } } ?> > Hi hadi: > > As http server is stateless, php can not know if a client has stop requesting. > you should do your trick on the client side. > > But if you insist doing this on the server, you may need to write a daemon > process or crontab job , here's the step > > 1. Everytime the client make a request, your php code write a timestamp in a > temp file. > 2. Your daemon process should read this file and compare to the timestamp > by NOW, if it is larger than you expect ,then do the if statement thing in the > daemon process. > > 于 2014年07月01日 08:21, hadi 写道: > >> You will have to make the script 2 parts. One to reload and the other > >> to execute the else (exiting). You need to use ajax to call the php > >> script every second (for the first part) and use the page's onunload > >> method to execute the second part (user exited): > >> > >> > >> http://www.w3schools.com/jsref/event_onunload.asp > > I already tried your method with onunload, the problem with onunload > > when I change the page the script getting execute. > > > > I already have javascript to pull php script, just I need php script > > doing the flowing; when javascript stop pulling php script. Block in > > if statement should run. > > > > Can you give me php script ? please. > > > >> On Mon, Jun 30, 2014 at 7:56 PM, hadi <almarzuki2011@xxxxxxxxxxx> > wrote: > >> > >>> I have javascript to pull my php script every interval of second. > >>> > >>> When javascript stop pulling my php script, block in if statement > >>> should execute. > >>> > >>> Can someone provide me with the php script please ? > >>> > >>> Thank you. > >>> > >>> > >> You will have to make the script 2 parts. One to reload and the other > >> to execute the else (exiting). You need to use ajax to call the php > >> script every second (for the first part) and use the page's onunload > >> method to execute the second part (user exited): > >> > >> > >> http://www.w3schools.com/jsref/event_onunload.asp
<<attachment: smime.p7s>>