Cron Jobs stopped working - php

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.

Related

WordPress and Mailpoet CRON

I have a WordPress with MailPoet.
Someone know if possible to schedule CRON task for Mailpoet ?
I have to send Newsletter every day (Monday to Friday at 5pm) only if there is a new content from specific categorie.
But i dont know how Mailpoet works. I would like to create a script php but i didnt find sometjing about CRON and MailPoet on Google ...
I have the last version and premium of MailPoet.
Thansk for your help.
The answer is on the Mailpoet website:
http://docs.mailpoet.com/article/47-configure-cron-job
2.4 Cron job commands to call MailPoet's Cron URL
Below are a few examples of commands you can use.
You'll only need to set up one on your server, so simply pick the one
which works on your server ( curl is safer):
curl --silent "http://www.yourwebsite.com/wp-cron.php?xxxx..." > /dev/null 2>&1
wget --quiet "http://www.yourwebsite.com/wp-cron.php?xxxx..."
Don't forget to replace http://www.yourwebsite.com/wp-cron.php?xxxx... with your
own MailPoet's Cron URL.
Some hosts may allow you to set up cron commands from their admin
interfaces. But, the commands wget, curl and lynx may not be
available, so if the cron doesn't seem to be running, get in touch
with your host and they should be able to help you out.

PHP- Sending a daily email

I am making a website that sends people who sign up for it an email every day in the morning. The problem I have run into is that I don't know how to send an email at the same time everyday in php. I do know how to send an email, all I need to know how to send one daily.
You can setup a CronJob for that. Only make the PHP that sends the email you want and prepare a CronJob in your server that executes every day (you can specify the time of the day).
I would use Tectite Formmail
If you have, for example, GoDaddy hosting, you can follow this instructions: CronJob GoDaddy
Yes, you need to run cron, it will already be installed and configured on your server.
To build-up your list, set up a form that subscribes people to your list, adding them to a database - don't forget to use double-opt-in.
Then write a PHP script that generates a message for everyone on your list and sends it to them - there is a code example that does exactly this bundled with PHPMailer. To let cron know how to run the script, make this the first line of the file (before <?php):
#!/usr/bin/env php
Finally, get cron to run it - this is trivially simple - just symlink it into /etc/cron.daily/ and it will get run when cron runs each day. Look in /etc/crontab to see when this is, and alter it if you like. For example:
ln -s /path/to/my/script /etc/cron.daily/myscript

Cron job not running on Godaddy

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

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/

How to run the PHP script at scheduled time

I need to run a php script at the scheduled time daily to update some fields in database and to send automated email. How I can do this?
Is it possible to write some service in XAMP server to run the script daily at scheduled time? I have no idea how to update database and send email automatically at the scheduled time. Can any one share some ideas or concepts?
I am using PHP and MySQL running in Linux Server.
You should use a Cron job to do it. Check out the examples on the Wikipedia page.
The Cron Job should call a script using the php executable that runs the necessary task.
Just create the script that does the required job, test it by hitting the URL in your browser once you are sure it works right. Copy the URL and add a Cronjob
Then schedule this command to run at whatever time you want to run
php ABSOLUTE_URL_TO_SCRIPT >> logfile
The log file is optional. But it will give you a chance to see what happened.
For example if you want to run your script every 4 hours, and assuming your script is at http://localhost/work/scripty.php and assuming that your http root is /var/www,
you would run "crontab -e" in terminal and add the following line:
* */4 * * * php /var/www/work/scripty.php
If you need more information just comment I will update the answer.
PHP cannot run script by itself,since php doesn't have daemons like python !!
So you have to take OS help to invoke your custom script .
For example in linux :
(example.sh)
export USE_PHP=php
cd $SCRIPT_ROOTDIR
$USE_PHP -f cronfile.php service="checkdatabase"
(service is the parameter passed to your cronfile).
For setting up cron jobs ,have a look at this link
http://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/
In Linux, We can create .sh file and can give a specific time to run that is called cron job.
SO should use this method just make a shell file and give a time period to it.
You should take a help with linux expert for that.
Use the following: Cron Job

Categories