PHP and scheduled tasks

Reply

Join Date: Jan 2007
Posts: 4
Reputation: Lothas is an unknown quantity at this point 
Solved Threads: 0
Lothas Lothas is offline Offline
Newbie Poster

PHP and scheduled tasks

 
0
  #1
Jan 11th, 2007
Have you ever seen (or played) one of those "Browser Games" where you build stuff, create armies and fight other players? Right now I need to know how to do those scheduled tasks...

I'm building a PHP appilcation for my job. I work at a visitors center and I want to create an application where you can add visits and let a worker to "add himself" to the shift. The server should perform some automated tasks like finishing the "registration" period for a shift and deleting or archiving a Visit after it has ocurred.

Would you mind pointing out how to do that with PHP?

P.S.: If there is an open source application similar to mine out there, I could use a link to it :cheesy:
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 138
Reputation: php_daemon is an unknown quantity at this point 
Solved Threads: 2
php_daemon php_daemon is offline Offline
Junior Poster

Re: PHP and scheduled tasks

 
0
  #2
Jan 11th, 2007
You have two choices:
  • Set up a cron job for the routine script
  • Call the routine on a common page (like index.php), save a time when it's executed and check against that so you can limit the execution times

The cron job option seems to make more sense.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 348
Reputation: paradox814 is an unknown quantity at this point 
Solved Threads: 4
paradox814's Avatar
paradox814 paradox814 is offline Offline
Posting Whiz

Re: PHP and scheduled tasks

 
0
  #3
Jan 11th, 2007
a cron job would be the ideal case, check with your host to see if they allow them.
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,075
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: PHP and scheduled tasks

 
0
  #4
Jan 12th, 2007
Originally Posted by php_daemon View Post
You have two choices:
  • Set up a cron job for the routine script
  • Call the routine on a common page (like index.php), save a time when it's executed and check against that so you can limit the execution times

The cron job option seems to make more sense.
If you want to call the routine job from a webpage, try this method I've blogged about: http://fijiwebdesign.com/content/view/86/77/


It allows you to set the job without delaying the sending of the web page to the user. Thus your job can go on for minutes or even hours (if your server allows it) and the user had no idea they initiated a routine job on your server.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 138
Reputation: php_daemon is an unknown quantity at this point 
Solved Threads: 2
php_daemon php_daemon is offline Offline
Junior Poster

Re: PHP and scheduled tasks

 
0
  #5
Jan 13th, 2007
Originally Posted by digital-ether View Post
If you want to call the routine job from a webpage, try this method I've blogged about: http://fijiwebdesign.com/content/view/86/77/


It allows you to set the job without delaying the sending of the web page to the user. Thus your job can go on for minutes or even hours (if your server allows it) and the user had no idea they initiated a routine job on your server.
Nice article. I didn't know about a possibility of performing tasks after rendering the page. Just got up and already learned something. Thanks.

I got a question though about the first method of using exec. Wouldn't it be a better idea to use the php CLI as opposed to wget? I mean the CLI version overrides the max_execution_time to unlimited while running it with wget it falls under the restriction (unless you set it in your script).
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 348
Reputation: paradox814 is an unknown quantity at this point 
Solved Threads: 4
paradox814's Avatar
paradox814 paradox814 is offline Offline
Posting Whiz

Re: PHP and scheduled tasks

 
0
  #6
Jan 13th, 2007
Originally Posted by digital-ether View Post
If you want to call the routine job from a webpage, try this method I've blogged about: http://fijiwebdesign.com/content/view/86/77/


It allows you to set the job without delaying the sending of the web page to the user. Thus your job can go on for minutes or even hours (if your server allows it) and the user had no idea they initiated a routine job on your server.
why not just use
  1. exec( 'php /home/username/routine_task.php > /home/username/routine_task.log &' );

using php allows you the ability to keep the code away from website so the code is not public (ie there is no need to place it in the public_html folder, it can be placed anywhere). No one will ever see, and you don't need any ie hacks.

Also since everything is now only related to your cron job why port everything to /dev/null ? I would recommend porting everything to say routine_task.log that way every day there is a log (that is overwritten so it will never grow to large in terms of the number of logs) of any errors that occurred on that script allowing you to fix any mistakes.
Last edited by paradox814; Jan 13th, 2007 at 5:18 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC