Jump to content
xisto Community
Sign in to follow this  
iGuest

Automatic/remote Php Script Execution

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 *BLEEP* windows).

Share this post


Link to post
Share on other sites

I use Xisto, 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!

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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. Xisto doesn't have Windows servers, only Linux ones :P

Share this post


Link to post
Share on other sites

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 Xisto 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 Xisto shout box, then you don't do anything with Xisto 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. :P

45 * * * * /usr/bin/lynx -source http://forums.xisto.com/no_longer_exists/
or

45 * * * * /usr/bin/wget -O - -q http://forums.xisto.com/no_longer_exists/


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. :P

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.