RE: [PHP] Re: session expire timeout
| From: | hadi | Date: | Sun, 29 Jun 2014 22:55:18 +0000 |
| Subject: | RE: [PHP] Re: session expire timeout | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-323558@lists.php.net to get a copy of this message | ||
> I hardly can make any sense of your description, but the following
comments
> might help you a bit.
Look when I open javascript page I will keep pulling my script "test7.php"
and keep it alive every interval second. When I close javascript page. My
script "test7.php" should timeout and execute "
file_put_contents('/tmp/phptest1234.txt', 'test');".
Hope im clear here. Did you get what I mean ?
> Hadi wrote:
>
> > I have session timeout set to 1 with while loop, it well keep looping
> > until session expire, then it well run my script "
> > file_put_contents('/tmp/phptest1234.txt', 'test');".
> > Also I have javascript to keep pulling the script to keep it alive
> > every interval time. If I close javascript page no more pulling the
> > script then it well timeout and run my script "
> > file_put_contents('/tmp/phptest1234.txt',
> > 'test');"
> >
> >
> > When I open javascript page it well call my php script and execute it
> > along with " file_put_contents('/tmp/phptest1234.txt',
> > 'test');".
> >
> > What I want here when I open javascript page it should keep pulling my
> > php script. And if I close the page timeout well happen to my php
> > script and execute my script " file_put_contents('/tmp/phptest1234.txt',
> 'test');"
> >
> > But this doesn't seems to work. How to accomplish this senior. Can
> > somebody give help here please.
>
> I hardly can make any sense of your description, but the following
comments
> might help you a bit.
>
> > Php code
> >
> > <?php
> > session_start();
> > ?>
> >
> > <?php
> >
> > $_SESSION['timeout'] = time();
> >
> > $st = $_SESSION['timeout'] + 1;
> >
> > while(time() < $st)
> >
> > {
> >
> > echo "$st\n";
> >
> >
> > }
>
> Instead of the while loop, you can use sleep
> (<http://www.php.net/manual/en/function.sleep.php>).
>
> > file_put_contents('/tmp/phptest1234.txt', 'test');
> >
> >
> >
> >
> >
> > ?>
> >
> > Javascript code
> >
> > <script type="text/javascript"
> > src="jquery-1.11.1.js"></script>
> >
> >
> >
> > <script type="text/javascript" >
> >
> > $(function(){
> > // set interval for 5 minutes
> > setInterval(function(){
> > $.ajax({url: "test7.php"
> >
> > });
> > }, 10000);
>
> 10000 doesn't mean 5 minutes, but 10,000 milliseconds (i.e. 10 seconds).
> This interval, however, is only an approximation by the nature of
JavaScript's
> event loop.
>
> > });
> >
> > </script>
>
> --
> Christoph M. Becker
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
Attachment: [application/pkcs7-signature] smime.p7s
Attachment: [application/pkcs7-signature] smime.p7s