Cron job not running on Godaddy - php

I've always used mysql events for scheduled tasks but my hosting doesn't allow the event scheduler to run. I've had to make the switch to cron jobs and I think I'm very close to getting them working. Spent hours reading tutorials and testing but no luck.
I have a cron job that I want to run every minute, here's what it runs:
/web/cgi-bin/php5 /public_html/velrania.com/cron.php > /dev/null 2>&1
The php file location is fine, the dev/null part is there to prevent email notifications (unless I've been misinformed) so I think it is the first part which executes php
I've tried changing the path to "/usr/local/bin/php -q" as directed by https://support.godaddy.com/help/article/3483/what-is-a-cron-job?countrysite=uk but that didn't work.

Ha, I'm stupid.
/public_html/velrania.com/cron.php
needed to be
/home/USERNAME/public_html/velrania.com/cron.php

Related

cron job on webserver

the last days I have researched about cron jobs. First I want to tell you abaout my problem.
I want to run a php script on my webserver every minute without loading the page. this php script inserts some data via yql. I read that cron is just working with unix/linux. my server runs on unix (wait for it). is it now possible for me to let my script run while sleeping in bed (computer off) just by the server side? do I got this all right? if yes, I also have to know how the path have to be look like in my command part in my schedule, because every example contents something like "* */1 * * * /usr/bin/wget http://www.example.com/cron.php", but why there is /usr/bin/wget in the path (that means, this cron is running just from my computer system not from the webserver) and how to put my schedule on the server and better where. my server have the root public_html where my index.php is inside. please give me an example of the schedule and how to fire my php data called "to_fire.php" that puts the data on my database via mysql.
I hope that some of you know what I exactly mean by own experience. im kinda confused by this command part and how to let it run from just the webserver and not my computer system.
thanks
wget is a unix command to visit a web URL. curl is another command working similarly. You could also use php path\to\script.php to run, as Gigawatt mentioned. There is no big difference from all of them
* */1 * * * is to set cron timing.
/usr/bin/wget is the location where wget on your server
Yes, once cron set, you can leave it alone. As long as server is living, the cron will run as scheduled. You can even set cron to send you an email, but that's no applicable to your case as running per min is to short.
Running cron per min seems not common. If you are doing something like realtime update, consider other solution.
Cron can be set on cPanel.
You need to config your cron script to accept request from same server only, to avoid others access this URL.
Some resource for cron
Configuring cron jobs in cPanel http://drupal.org/node/369267
Backup Databases using a cron http://wiki.lunarpages.com/Backup_Databases_using_a_cron
Configuring cron jobs using the cron command http://drupal.org/node/23714
Managing Cron Jobs with PHP http://net.tutsplus.com/tutorials/php/managing-cron-jobs-with-php-2/

PHP Daemon Script

I was wondering how to make a php daemon script that runs one time at the day?
Do you know any good frameworks with benefits?
or is it just small code?
Thanks
I was wondering how to make a php deamon script that runs one time at
the day?
In order to do this, get familiar with cron jobs. A cron job is a function that gets executed by the server on a time interval. Usually you'd edit your "crontab" by executing crontab -e
Then, once inside, you'd write the interval you want, followed by the command.
Typically it looks like:
30 18 * * * rm /home/someuser/tmp/* > /home/someuser/cronlogs/clean_tmp_dir.log
Since its PHP, you can either a) run your php command as a php cli command, OR b) you can make the command get executed when a particular page is run... and just execute that in cron via a curl -X GET 'http://url/' (etc.)
Also, note that you can write all of your stuff in a shell script file and actually run that file as your cron command... that reduces line-item complexity
cron
Sorry I haven't closed this one.
I actually discovered that my host didn't allowed cron jobs running. So I found a relevant homepage that offer a free service to make a request for me when I needed. In my case, I have specified a url link that should be requested to my RESTful API each day.
The link is here and works like a charm :)

Run PHP file at scheduled times?

I have a php file which pulls some data from external API's, and I want to schedule it to do so every few hours (or every few days). Some googleing led me to "scheduled tasks", but it seems I need to be running my own server to do it?
So far, all the PHP and MySQL I've done have been very simple form-filling, so I'm a little lost. Do I need to turn a computer into a server to do this, or should I look into hosts that allow you to run scripts? I'm not exactly sure what I'm looking for.
Side-question: how would I be able to prevent someone else from running the PHP script (therefor making tons of API calls)?
How are you running the script now? Windows or Linux? Linux is a no-brainer with cron: on a PHP-enabled server simply drop the PHP script somewhere, edit the crontab and away you go!
Ex. for every 2 hours
0 */2 * * * /usr/local/bin/php /path/to/script.php
Edit Re: Mac
launchd is apparently the preferred method to run scheduled tasks but I understand that OS X has cron capabilities as well being a UNIX derivative.
If you have a reasonably busy web server, you can simply check every time how long it has been since the last time you ran the script. If more than two hours, run it.
Just make sure to update the time and run the script atomically so you don't launch several copies of the script. You can do this with a file that contains the last time the script was run that you lock while you check and update it.
cronjobs are made for it... You can check the Cron Jobs in cpanel..
I am assuming your website is launched in Linu environment
http://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/
http://man.cx/cron
You can find much more exlaination about the Background Process
http://www.fijiwebdesign.com/blog/create-a-background-process-on-the-server-with-php.html

Getting a php script to run at a certain time each day independently each day?

I am in need of something like this I need a script to run independently each day at a certain time without fail, the script will be for PDO mysql and some other things,
Can anyone point me in the right direction??
Thanks
If PHP is configured to run from the commandline you can simply setup either a cronjob (crontab -e) (Linux) or a scheduled task (Windows) where you run the php file(s) you want to run.
php -f /path/to/script.php
If you're on Linux, use a CRON Job. For Windows, use a Scheduled Task.
There are also services that do this online. A quick Google search returns this site.

Cron Jobs stopped working

I've been running a daily cron job for a few months and it was working fine.
The cron job runs a php script that does a database action then mails my email address with the results.
Suddenly a few days ago, when the script ran, the database action stopped working, but it would send me the email. I changed the php script to send a different email, but it still sends me the old one.
I can't seem to get any new scripts to run and when I set up an email address for the cron job to run it doesn't send one.
Any thought as to how I can get this back on track?
More information:
I use a linux OS cPanel.
I've used the following commands.
/usr/bin/php -f /home/[user]/public_html/[path to script]
/usr/bin/php -q /home/[user]/public_html/[path to script]
/usr/local/bin/php -f /home/[user]/public_html/[path to script]
/usr/local/bin/php -q /home/[user]/public_html/[path to script]
PHP says that the path to PHP is /usr/bin/php however, it used to work with the local part in there.
#DampeS8N- I'd rather not. The PHP script just includes a few sql commands and a mail function. It works fine without any errors when visited by browser.
#Paul- That is what I am inclined to believe. I think the Cron Daemon is stuck somehow. When I try to add new cron jobs, they don't register as going off, and it won't send emails to my email address when a cron should go off.
I am a complete newbie to cron. I access cron jobs in my cPanel X. I'm pretty sure I don't use crontab. Detailed instructions for any actions you'd like me to take would be great.
Well, I wound up contacting my hosting support. Turns out the domain was moved to a new server and the cron jobs were still running on the old one.

Categories