Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Automatic/remote Php Script Execution
Habble
post Jul 18 2007, 05:57 AM
Post #1


Premium Member
Group Icon

Group: [HOSTED]
Posts: 286
Joined: 17-June 07
From: Tasmania
Member No.: 22,699



Hi, I was wondering, is it possible to execute a PHP script when a user isn't on the page with it? Say for example, have it so that a script checks that if a certain time has passed since a user was last active, it logs them off? So that if they've closed the window, it doesn't keep them marked as logged in.

Also, is there any way, with PHP to alert a user when something changes, as soon as it happens? Say that if they recieve a new message, a box pops up telling them? You could do this with Ajax I suppose, but (correct me if I'm wrong) continually running a script to check it would slow the user's browser down considerably.
Go to the top of the page
 
+Quote Post
Jeigh
post Jul 18 2007, 11:22 AM
Post #2


Whitest Black Mage
Group Icon

Group: [MODERATOR]
Posts: 1,352
Joined: 20-May 05
From: NB, Canada
Member No.: 5,281



I don't know the specific php to accomplish these things as I haven't done any php recently and don't feel like looking up a refresher haha, but the theory seems straight forward enough.

For the first, you could simply store in your db a kind of "last access" time for the user, I'm sure there are easily found php scripts to log when users do any significant action, and then just every 5 or 10 minutes compare all the users that are logged in currently lastest access times to the current and if its over whatever threshold you want log that user out.

The popup would be similar, I assume you could just set up something to check every 10 or 15 seconds if there is a new message waiting, a simple boolean type flag check would suffice, then if there is retrieve it and pop it up, otherwise continue on. This wouldn't slow it down much I don't imagine since its just a quick check on an interval. An infinite check loop would slow things down but a timed one less so.

I assume someone with more specific php knowledge will show up soon enough, but I figure I'd throw out some ideas to maybe point you in a direction at least worth thinking about.
Go to the top of the page
 
+Quote Post
Habble
post Jul 19 2007, 05:35 AM
Post #3


Premium Member
Group Icon

Group: [HOSTED]
Posts: 286
Joined: 17-June 07
From: Tasmania
Member No.: 22,699



That's not what my problem is. the problem is getting it to check at intervals, even when the user isn't on the page
Go to the top of the page
 
+Quote Post
pyost
post Jul 19 2007, 10:31 AM
Post #4


Nenad Bozidarevic
Group Icon

Group: [MODERATOR]
Posts: 1,013
Joined: 7-November 05
From: Belgrade, Serbia
Member No.: 9,500



There is no way to notify the user as soon as something happens, but checking it in equal intervals with AJAX seems like the best solution. You just need to create a JavaScript function that would check if there is anything, and then call itself again in let's say 15 seconds.

As for the "Last Active" problem, one way is to check it when any script is accessed. For example, User1 closes his/her browser, and then there is not activity on the web site whatsoever - nothing is deleted. However, when User2 requests a certain page (doesn't matter which one), you first run the "last active" script, in order to clear user that left, and then display the page User2 requested.

I think it might also be possible to achieve this with cron jobs, but I have never used them, so can't tell you with certainity.
Go to the top of the page
 
+Quote Post
ethergeek
post Jul 19 2007, 09:37 PM
Post #5


Premium Member
Group Icon

Group: [HOSTED]
Posts: 393
Joined: 9-March 07
From: Tucson, AZ
Member No.: 20,794



QUOTE(Habble @ Jul 18 2007, 10:35 PM) *
That's not what my problem is. the problem is getting it to check at intervals, even when the user isn't on the page


Use a cron job to do it. Create a PHP script which does the checking and use the PHP cli from a cron job to execute it. If you don't have access to a PHP cli executable, you can do the same thing with perl, and I can't imagine a web host that doesn't have perl installed on it (unless its shitty windows).
Go to the top of the page
 
+Quote Post
Habble
post Jul 20 2007, 05:34 AM
Post #6


Premium Member
Group Icon

Group: [HOSTED]
Posts: 286
Joined: 17-June 07
From: Tasmania
Member No.: 22,699



I use astahost, and I'll try it with cronjobs (I don't know perl).
I didn't think cronjobs would be able to do it, but I'll try it! Thanks!
Go to the top of the page
 
+Quote Post
Sten
post Jul 20 2007, 07:39 AM
Post #7


Oh come on Mrs. B!
Group Icon

Group: Members
Posts: 648
Joined: 6-June 07
From: Tasmania, Australia
Member No.: 22,422



i dont no wot php cli executable is, lol.
i dont no how to use a cronjob.

but ethergeek, since perl isnt on windows, wouldnt ASP be the windows alternative or something maybe?
Go to the top of the page
 
+Quote Post
toby
post Jul 20 2007, 09:31 AM
Post #8


Super Member
Group Icon

Group: Members
Posts: 511
Joined: 29-September 06
Member No.: 16,228



QUOTE(Sten @ Jul 20 2007, 08:39 AM) *
i dont no wot php cli executable is, lol.
i dont no how to use a cronjob.

but ethergeek, since perl isnt on windows, wouldnt ASP be the windows alternative or something maybe?

The exe, not the parsed version you see on the web. Cli == command line inferface, like command prompt.
Hard, google.
Doubt it, Asp is more equal to php.
Go to the top of the page
 
+Quote Post
FirefoxRocks
post Jul 22 2007, 04:12 AM
Post #9


Super Member
Group Icon

Group: [HOSTED]
Posts: 702
Joined: 12-July 06
From: Ontario, Canada
Member No.: 14,464



You can execute cron jobs at specified intervals to check if a script has been accessed in the last # minutes I think. I don't know how to do this, but I think it is possible because it seems like reading from MySQL.

Keep in mind that AJAX is your friend when making server requests but not reloading the entire page.

Astahost only supports PHP+MySQL, not ASP+MSSQL. Astahost doesn't have Windows servers, only Linux ones smile.gif
Go to the top of the page
 
+Quote Post
Quatrux
post Jul 22 2007, 05:37 AM
Post #10


the Q
Group Icon

Group: [HOSTED]
Posts: 1,054
Joined: 13-July 05
From: Lithuania, Vilnius
Member No.: 7,059



Cron Jobs is easy to use, for those who thinks that Cron Jobs is a hard thing, even CPanel can manage them, just go to CPanel on Astahost and enter Cron Jobs, I prefer the advanced version and just search for google how people do it, usually they just execute Links browser to access the php file and set the time period you want to do it.. Anyway, by doing that, you can only refresh the database with say active/online users and set them to not be shown in the online users list, you can't actually send data to a user whom browser is opened and he can't see a notice or something and for that reason Cron Jobs are useless here, because you can just do it in the php script, check the current time with the time in the database and parse the online users list or something.. I mean, who the hell cares about the online list or users logged when you have no visitors, when a visitor comes online or reloads the page, just check it with PHP and parse the required data, log everyone out and etc. this is quite very easy to do and no need of cron jobs and for real time things, like here on astahost shout box, then you don't do anything with astahost dot com, a message/notice is shown that seems you're away or something and you need to push the I'm back form button to return, this all is done with AJAX and you should stick to it, due to when you use cron jobs you send all the headers and data to Links/Lynx or WGet browser, not to a user. tongue.gif

QUOTE
45 * * * * /usr/bin/lynx -source http://example.com/cron.php

or

45 * * * * /usr/bin/wget -O - -q http://example.com/cron.php


This would have a browser (lynx or wget) visit your cron page 45 minutes after every hour, this is how I did it on Drupal CMS, I found an explanation for this on their support pages. Notice that when using it, after a while I got cron jobs errors, I couldn't access lynx anymore so I stopped using this feature, it might have been that somebody blocked access to it for security reasons, it was within this year or maybe a year ago. wink.gif
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. How To Make A Text Based Online Game Script ?(23)
  2. PHP: Writing A Generic Login And Register Script(14)
  3. How To Save A Image In Pdf File And Download It?(10)
  4. Bash Script To Display Your Ip(9)
  5. Help Needed To Create Login Script With Perl/cgi(21)
  6. Need Help With A PHP - MySQL Registration Script(13)
  7. PHP Tutorial: Form Verification And Simple Validation(12)
  8. Create And Import JavaScript Modules For A Large Script(2)
  9. Running Vba Script In Excel(6)
  10. Awesome Remote Control Software!(18)
  11. Rpg For (php)wml Script Text Based(1)
  12. Very Simple Login-script(18)
  13. Attack Script In Php(5)
  14. A Simple Register Script(3)
  15. Auto-click Script(7)
  1. Myspace Gold Script(2)
  2. Looking For Script(5)
  3. Free Login Script(1)
  4. Php Login Script(0)
  5. Pause A Command Prompt After Execution?(5)
  6. Creating A Php Login Script(3)
  7. Myspacetv Download Php Script Help(6)
  8. Database Access On Remote Server W/jsp(0)
  9. Free Remote Wireless Server?(1)
  10. Automatic Typing Script(3)
  11. Remote Desktop Software(7)
  12. [fl]snow Effect(4)
  13. Teamviewer(7)


 



- Lo-Fi Version Time is now: 13th October 2008 - 04:35 AM