Cron jobs

  • Paul
  • Newbie
  • Newbie
  • Paul
  • Posts: 9

Post 3+ Months Ago

I was wondering what an example command would look like to run a cron job for a php file. eg in folder WD - php file UPDATE.PHP
I'm not real familiar with cron jobs, any help would be appreciated.

Thanks
Paul
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9086
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

You will need to find out the answer to the following question, "Is my PHP installed as CGI or as an Apache module?". To find out do the following: Create a new file, name it info.php (just an example), and put in the following code, "<? phpinfo(); ?>". Upload to your webserver and go to it with your browser.

Now check for Server API (4th item from the top), if it says "CGI", you have PHP compiled as CGI, if it reads "Apache", you have it running as an Apache module.

IF CGI
If the answer to the question above is "CGI" then you need to add a line to your PHP script. It has to be the first line of your script and must contain your server's PHP executable location:

#!/usr/local/bin/php -q

That looks a lot like PERL now, doesn't it? After that let's add the necessary command to our crontab. Edit /etc/crontab and add the following line:

* * * * * php /path/to/your/cron.php

Execute the following from the command line:

crontab crontab

Be sure your "script.php" has the necessary permissions to be executable ("chmod 755 script.php").

Now you are all set!

IF APACHE MODULE
If your PHP is installed using the Apache module, the approach is a little different. First, you need access to Lynx (click here for more information ). Lynx is a small web browser, generally available on Unix and Linux.

Running your PHP script will not require you to add any additional lines. You simply have to edit your /etc/crontab file and add the following line:

* * * * * lynx -dump http://www.somedomain.com/cron.php

Please note that in general, you have to specify the entire URL (with "http://" and so on). But depending on your Lynx's configuration, the URL might be relative; I suggest always using the absolute reference as in my example above - it always works.

Again execute the following from the command line:

crontab crontab

That all it takes to get a cron job setup using PHP.

I found this information from the following link if you want more info:

http://www.webgfxcenter.com/tutorials/t ... m/155/PHP/

If you need anymore help or aren't understanding how to do something let us know :)
  • Paul
  • Newbie
  • Newbie
  • Paul
  • Posts: 9

Post 3+ Months Ago

Thank you once again. Once I was able to upload the proper rpm for lynx, everything worked out well from there.

Thank you
Paul
  • jmwebm3
  • Born
  • Born
  • jmwebm3
  • Posts: 1

Post 3+ Months Ago

I am sorry for bringing up an old thread BUT I have a few questions..
I ran phpinfo() and discovered that PHP was compilled as CGI. I then added in the line, as described above, to my php file.

My question is the following:
Can the PHP script timeout when runnning via a cron job?

Is the cron job "like" a browser where I have to worry about timing out issues?

Also, is the PHP executable location listed in phpinfo()? I just copied the location suggested above.

Thanks in Advance.

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 12 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.