Jump to content


cron php script

  • Please log in to reply
3 replies to this topic


  • Members
  • PipPip
  • Member
  • 15 posts

Posted 17 May 2006 - 12:08 PM

I have a php page that displays "Online" and "Offline" statuses for different hosts. It works by attempting to open a socket to those hosts. Because this can be a time intensive task to for 3 hosts every time the page loads, the page often is very slow to fully load. So how can I make the php script run with cron? That is, every 10 minutes run the status checks on the hosts and save the results in a flat text file or something. That way the website can just read the text file. This should dramatically reduce the loading time of the pages. I know about cron and how to add to it. So do I just put in cron the php script? I dont think the server can run the php script if it's not initiated in apache. So im lost. How do I make cron be able to run a php script much like apache would? Ive seen this done before with news sites and such. Thanks in advance!


#2 Kris

  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 17 May 2006 - 01:02 PM

The command would be something like:

0 3 * * * /usr/local/bin/php /usr/home/*username*/public_html/script.php

The second part of the command "/usr/local/bin/php" points to the PHP install on the server, the script is run through the command line rather than through Apache.


  • Members
  • PipPip
  • Member
  • 15 posts

Posted 17 May 2006 - 06:42 PM

Awesome! Thanks SemiApocalyptic!

#4 SharkBait

  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 19 May 2006 - 07:56 PM

Instead of using /usr/local/bin/php

I've used the lynx text webbrower and pointed it to the php file.

Though I'm sure its quicker to do the other ;)

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users