How to run PHP Scripts with crontab make php files executable

RegisterLogin
How to run PHP Scripts with crontab make php files executable
Post Description: How to run PHP Scripts with crontab make php files executable
Tags: How, to, run, PHP, Scripts, with, crontab, make, php, files, executable
This Post Was Posted On Feb 29, 2008 By unix admin #871
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
Leave Your Comments
Related Pages: [Add Your Website]
Post New Topic
collins
#9684 1
$ php -q path/to/script.php
Apr 29, 2012 Reply Report abuse
hostman
#1128 2
oooof.. thanks for that tip
Jan 16, 2008 Reply Report abuse
[EviL]
#1127 3
just an extra command opinion:
* * * * * wget somedomain /cron.php
or
* * * * * wget -o /dev/null somedomain /cron.php
will also work :)
Jan 16, 2008 Reply Report abuse
linux help
#1126 4
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.
Jan 08, 2008 Reply Report abuse
Leave Your Comments...
©2013 Webune Forums - Wed Apr 24, 2013 8:22 pm
Powered by: Webune Forums V3