How To Run PHP Scripts With Crontab Make Php Files Executable
how to run php scripts with crontab make php files executable
how, to, run, php, scripts, with, crontab, make, php, files, executable
How To Run PHP Scripts With Crontab Make Php Files Executable
Post Description: how to run php scripts with crontab make php files executable
POST# 261
Posted On: Fri Feb 29, 2008 12:01 pm
unix admin
Topic: How To Run PHP Scripts With Crontab Make Php Files Executable
i need clean mysql database every day and i want to know if you can tell me how to do this from the shell. i got the dedicated server from you guys at www.webune.com but i still need to know if you can help me with this because its making my files go big and im running out of space

thanks


Tue Jan 08, 2008 11:54 am
1
linux help
Reply #790
well, first you need to find out if how your apache was compile, then you do this:

[ click here to find if apache was installed with CGI or APACHE module ]


Compiled 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:

Shell> crontab crontab

Be sure your "script.php" has the necessary permissions to be executable ("chmod 755 script.php"). Now you are all set!
Apache module
If your PHP is installed using the Apache module, the approach is a little different. First, you need access to Lynx (Lynx Browser 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:

Shell> crontab crontab

That all it takes to get a cron job setup using PHP. Hope you have learned something new and will use it to save overhead time on the server and on the developer.
Wed Jan 16, 2008 3:00 pm
2
[EviL]
Reply #791
just an extra command opinion:
* * * * * wget somedomain /cron.php
or
* * * * * wget -o /dev/null somedomain /cron.php
will also work :)
Wed Jan 16, 2008 5:06 pm
3
hostman
Reply #792
oooof.. thanks for that tip

What do you think?

* name:  

* email:  

* Please enter comments:


Receive Replies on my Comments
(An email will be sent to you when someone replies to your comments)

Add image to comments
yes no             upload