WordPress and Mailpoet CRON - php

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.

Related

Created a cron job in wordpress But the logs are displayed only when someone visits the page

In wordpress, I have worked to create a cron job.Currently, The Cron job displays the logs only when somebody visits the page. But, i want it to run without any page visit. I know that can be done. But how , that is what i dont know. Please guide me friends. I have used the function wp_scheduled_event
This is normal behaviour. Wordpress crons are not server crons, they depend of PHP to be executed, so it'll run only if someone visit your website.
From wp_schedule_event documentation:
The action will trigger when someone visits your WordPress site, if
the scheduled time has passed.
You'll need a server cron if you want to get through this limitation. Depends of your hosting, you may be able to configure a cron through the manager, or if you have SSH access on your server (so if it's not a shared hosting), execute this command :
crontab -e
It'll open your crontab file. Add this line inside to add a cron job:
*/30 * * * * php-cli -f /path/to/your/php/script.php
Replace with the correct path to your php script. This command will execute the script every 30 minutes - change this to whatever you need (read more).
If you're on a shared hosting and your manager doesn't allow you to create cron jobs, you could maybe use an online service like this one to execute your script.

Created a plugin for cron job in wordpress but how to connect it with linux without anyone visiting the site

I have worked on creating a plugin for setting a cron job. However it runs only when a person visits it. Can we link it with linux so that it opens the site and the cron job is done without anyone visiting the page. How can we use wget for this if the wordpress is set up locally?
Do this following steps to get your server cron going, enable server cron from plugin is not possible as of now (as i understand).
Disable wp-cron.php
You can disable WP-cron by modifying the wp-config.php (located in the folder where WordPress is installed). Open the wp-config.php file, add a new line after
define('DISABLE_WP_CRON', true);
Set Up a Linux Cron
Warning: It is important that you familiarize yourself with how cron
jobs work. You need to have a working knowledge of Linux commands
before you can use cron jobs effectively.
To set up a Linux cron job:
Log into your cPanel.
In the Advanced section, click Cron jobs.
Under Add New Cron Job, select the time interval. HostGator recommends that you do not set the interval lower than 15 minutes.
Set the cron command to the following, replacing yourwebsite.com with your actual domain name:
wget -q -O - http://yourwebsite.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1
The above command tells the Linux server to run wp-cron via wget, which will trigger the wp-cron.php script to do it's job on your schedule instead of on each page view.
Click Add New Cron Job to set the cron.
In order to test out the new cron, simply wait for the elapsed time period for the cron to run. In the event that the cron does not run, please review the steps listed above to ensure that you have completed all steps correctly.
CREDITS:
http://support.hostgator.com/articles/specialized-help/technical/wordpress/how-to-replace-wordpress-cron-with-a-real-cron-job
You can schedule a cronjob.
$ crontab -e
*/1 * * * * curl -I http://example.org/wp-cron.php?doing_wp_cron

Scheduling tasks in PHP without cron

Is it possible to schedule a task with PHP? like, I want to choose a date with the jQuery datepicker, and submit it. When that date equals today's date, an email will be sent for example (or any other PHP script). The date will be different depending on the user, also, every user can have a number of scheduled tasks to run.
EDIT
The OS is Linux, and the website is hosted on godaddy.com
Also, it's the end users who will choose when to run these tasks, so they can use command lines for that.
EDIT
Any Ruby on Rails or Django solutions are welcomed as well.
If you're using a Unix server, try at.
http://www.manpagez.com/man/1/at/
It works in a similar way to cron, in that it's totally separate from PHP, and you need to shell_exec() an external command. However, it has a simple command-line interface. Like cron jobs, at jobs survive reboots.
If you use at you'll have to write a separate script to perform the task you want scheduled.
Example:
shell_exec("echo 'php script.php' | at -t 201208011234.56");
Will run script.php on August 1st, 2012 at 12:34:56.
You need some process in the server side to run the task at the scheduled time.
A popular approach is to store the task information in some database and have a cron job checking the task queue from time to time - it is very reliable and safe.
It is impossible to give a better answer without more information about the environment where it will be deployed. For example:
target OS
hosting type (dedicated, shared, cloud)
do you have administrator privileges?
is it exposed to the internet?
Most likely you will not be able to do that in a shared hosting environment, anyway, but I must say that having a website calling shell_exec is not very wise from a security standpoint, so I would avoid that if the site is exposed to the Internet.
A good hosting provider should have some kind of background task scheduler available, even if it is not crontab. If your hosting provider hasn't, trying to pull some stunt to fill the gap probably is a bad idea.
[update]
As I said in the edited part of the original post, I'm hosting it on godaddy.com, and I can't let the clients run these command lines etc. Is there a solution with other languages too?
I'm not hosting at godaddy anymore but they used to have a "Cron Manager" at their control panel. I think the correct goDaddy cron setup is
/usr/bin/wget -O - -q "http://yoursite.com/cron.php" > /dev/null 2>&1
at the Command Option in the Cron Manager. This "cron.php" will check the task queue to see if there are any email to send (the task queue being a simple table in your database where you will record any task scheduled by your customers).
You can do this without cron by simply adding a check into the main index page, or a standard include file - but that's only for when you really can't get access to cron (e.g. shared hosting). In this check you'd grab the list of outstanding actions and execute them, possibly by using
if (time_since_last_run > 5*60) // minutes
shell_exec("/usr/bin/php /var/www/check-tasks.php &");
The best solution is to use cron to launch a PHP script that will check for scheduled items within your system and execute them. You can either do this via wget or directly via calling PHP.
One shared hosting site that I have is externally scheduled from another of my servers via cron and wget http://othersite.example.com.
example crontab entry:
0 * * * * wget -O - -q -t 1 http://othersite.example.com/cron.php

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

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