Ok, I want that on the 1st day of every month an email is sent to me to remind me of something about my website. So, I know how to make the PHP script to send the email, BUT I don't know how to make it as a cron job. I have toastedpenguin hosting, so I login the cp, go to cron jobs, select the time and date etc... and then what is the command I have to write to execute the PHP script?
Should I add some other code to the PHP script that send the email?
Thanks.
PHP as a cron job
Started by TcM, May 17 2008 07:01 AM
12 replies to this topic
#1
Posted 17 May 2008 - 07:01 AM
|
|
|
#2
Posted 17 May 2008 - 07:57 AM
If you'd like to execute the PHP script directly, you can run "php -f /path/to/script.php'.
Or if you'd like it to run as a web request, you can run "curl http: //example.com/script.php > /dev/null".
(Remove the space between "http:" and "//". It won't let me post this comment with a complete URL.)
Or if you'd like it to run as a web request, you can run "curl http: //example.com/script.php > /dev/null".
(Remove the space between "http:" and "//". It won't let me post this comment with a complete URL.)
#3
Posted 17 May 2008 - 09:36 AM
What is the difference between the direct and web request?
#5
Posted 17 May 2008 - 12:33 PM
TcM said:
What is the difference between the direct and web request?
PHP 4.3 included a server application programming interface (SAPI) which was the CLI (command line interface) which allows php to be executed directly from a console (bypassing the need for a webserver [Apache]). Long story short, using a web request will require Apache, the other method wont. I always run my crons directly using php -f.
#6
Posted 17 May 2008 - 01:45 PM
this is a great thread.... I always wanted to know how to do this.
I can just use this in SSH?
I can just use this in SSH?
Checkout my new forum! http://adminreference.com/
#7
Posted 17 May 2008 - 01:51 PM
After reading John's post, I think it is possible.
So the command should be something like this??
So the command should be something like this??
php -f /public_html/script.php
#8
Posted 17 May 2008 - 02:41 PM
phpforfun said:
this is a great thread.... I always wanted to know how to do this.
I can just use this in SSH?
I can just use this in SSH?
TcM said:
After reading John's post, I think it is possible.
So the command should be something like this??
So the command should be something like this??
php -f /public_html/script.php
Yes, but you need the full path to your script. Which is /home/<usrname>/public_html/script.php
#9
Posted 19 May 2008 - 10:41 AM
John said:
Yes, use the same command below.
Yes, but you need the full path to your script. Which is /home/<usrname>/public_html/script.php
Yes, but you need the full path to your script. Which is /home/<usrname>/public_html/script.php
THread bookmarked**
ok, what if I want it to execute at a certain time.. do I put that time in the line, or in the script?
Checkout my new forum! http://adminreference.com/
#10
Posted 19 May 2008 - 01:42 PM
phpforfun said:
THread bookmarked**
ok, what if I want it to execute at a certain time.. do I put that time in the line, or in the script?
ok, what if I want it to execute at a certain time.. do I put that time in the line, or in the script?
In cPanel, there is an interface which allows you specify time and dates for the cron to run.
#11
Posted 19 May 2008 - 02:29 PM
What if I didnt have cpaneL? Like if I were on a friends server and wanted to set one up, but he doesnt have cpanel
Checkout my new forum! http://adminreference.com/
#12
Guest_Jordan_*
Posted 19 May 2008 - 02:40 PM
Guest_Jordan_*
You can login via SSH and execute the command:
which is what cpanel executes. Also, on top of what John said (and I also learned this from John) you can put the PHP shebang at the top of your PHP script and execute it like a shell script:
I'd also like to point out another method that circumvents the crontab. You can have your PHP script check for a date. For instance, if you want to execute on the 1st at 12:00 you can use the date function to check the date and time. If it is the 1st and 12:00 or after the script will execute. You would include this PHP in your webpage so it is actually activated when users visits (every time they visit it checks the date time). I think that using the crontab is better but I point this out in case some users do not have the ability to access the crontab. vBulletin also uses this method.
# crontab -e
which is what cpanel executes. Also, on top of what John said (and I also learned this from John) you can put the PHP shebang at the top of your PHP script and execute it like a shell script:
# ./myPhpScript.php
I'd also like to point out another method that circumvents the crontab. You can have your PHP script check for a date. For instance, if you want to execute on the 1st at 12:00 you can use the date function to check the date and time. If it is the 1st and 12:00 or after the script will execute. You would include this PHP in your webpage so it is actually activated when users visits (every time they visit it checks the date time). I think that using the crontab is better but I point this out in case some users do not have the ability to access the crontab. vBulletin also uses this method.


Sign In
Create Account


Back to top









