What will be the best way to activate WordPress cron if your site has no hits or visits?
Just starting out my new DAILY BIBLE QUOTE blog and I have no hits yet. I have scheduled a post to published “once every day at 6:00 AM”. Since I have no hits I’m afraid the scheduled post will not get published, so i add cronjob on my shared cpanel hosting using the code below:
0 6 * * * wget -O /dev/null --timeout=120 http://example.com/wp-cron.php?doing_wp_cron=true
So my question is,
Will the scheduled post gets published using the command above or querying only the site http://example.com/ on the cron command is enough to do the job?
Do i need to scheduled the post at 6:05AM and add crontab to run at 6:00AM?
Do not run cronjob on the site hosting since the IP is going to be same, so better use a cron service like EasyCron using the FREE plan https://www.easycron.com/user/plan since the IP is going to be different so that my site will think of it as a new visit, hence activating wp-cron.
To address your questions:
Yes, you would simply need to load the homepage of your site (though you could load any page of the site) to trigger the WP Cron event. When you load the WordPress stack, on any page, it will load the entire WordPress stack and part of that loading is checking the database to see if any cron events are ready to run. The cron information is saved in the database with information on the time the next instance of that cron runs and the function/hook to run at that time, if anything matches it will fire off the event.
For more information on WordPress cron, you can review their documentation here:
https://developer.wordpress.org/plugins/cron/
Why not schedule the post at 5:59AM and then run the cron at 6AM? That would ensure that it gets published right on the minute.
Related
Lets say i have a job that runs for 10mins(lets say the time as 10.00). i set max_run_alarm as 3. i should get an email at 10.03 where i can goahead and see why the job is running more than the max_run_alarm. if i use max_run_alarm i am able to see in the logs triggering that alarm, but I cannot spend all day monitoring the logs to see which job is taking long as i have many jobs. my question is am i using max_run_alarm in the correct way or is there something else i am missing or is there entirely different way for the emails to generate.
There is an added functionality where you can configure the email id where all Autosys notification to be sent out.
Incase of any event such as Job Failure / Termination / Run Alarms etc are notified to that email address.
This is configured by the Autosys Admin or the Scheduling Team which i call them as.
Suppose I have a Wordpresss cron job scheduler function ( which runs only on page loads ) on server as follows :
add_action('init','create_single_schedule');
add_action('single_cron_job','single_cron_function');
function single_cron_function(){
Do cron here
}
function create_single_schedule(){
//check if event scheduled before
if(!wp_next_scheduled('single_cron_job'))
//schedule event to run after 60 seconds (or one minute)
wp_schedule_single_event (time()+60, 'single_cron_job');
}
Now the problem is if no one opens my website , how can i call create_single_schedule() to schedule/trigger a cron job ?
You have to set up a real cron job on your server to call wp-cron.php at your desired interval.
First, disable WordPress cron on wp-config.php:
define('DISABLE_WP_CRON', true);
If you have cPanel, set up a cron job to run every 5 minutes, or every hour and to execute the command:
wget http://www.example.com/wp-cron.php
More info:
Hooking WP-Cron Into the System Task Scheduler | Plugin Developer Handbook | WordPress Developer Resources
Should I disable WP_CRON and instead trigger wp-cron.php from server every few mins?
Insights into WP-Cron: An Introduction to Scheduling Tasks in WordPress
We're running Wordpress in an environment that features a multi-master DB behind a load-balancer. The error log was filling up with a deadlock error when WP tried to update the cron table in wp_options. We disabled wp-cron altogether but are still seeing the error, so, two questions:
1) What causes the cron table in wp_options to be updated?
2) It appears to run on every page load. Can this be disabled and a cronjob setup to run it periodically in crontab?
Thanks
Wordpress uses wp-cron.php as a means for running scheduled tasks when the user doesn't have access to or want to setup cronjobs via Unix. This process looks at the scheduled jobs in the cron table in wp_options and if the specified time (or more) has elapsed then the job executes.
wp-cron.php uses wp-includes/cron.php (the Wordpress Cron API) to run scheduled jobs. In cron.php you'll find a number of functions that update the cron table table, these functions are all around the scheduling of events.
Any function of Wordpress or plugin that requires a scheduled event uses the Cron API to do so. However, the action of scheduling an event (even if it already exists) updates the cron table in wp_options. Even with wp-cron.php totally disabled, these elements of Wordpress/the plugin are loading and scheduling their events, trying to update the cron table in the process.
I've not figured-out exactly why the deadlock occurs, other than knowing it must be related to the DB/site config, but I do now know that Wordpress is behaving itself.
I've run into this same issue -- the databases would go out of sync very quickly. Certain plugins made it occur faster (they scheduled lots of cron jobs), but even with them disabled, eventually the errors would block replication.
I was able to keep replication working by doing two things.
The first, in my.ini, was to add:
slave-skip-errors = 1062
This instructs MySql to skip creating entries when a duplicate key already exists. My cluster is set up as active-passive, so in theory, there should be no "real" writes to the passive MySql node unless the active node is down, in which case, there will be no "real" writes to that node. The only stuff that gets written to the passive node is as a result of wp-cron jobs, which (in theory) are also running on the active node.
The second, in each site's wp-config.ini, was to add:
/** disable cron */
define('DISABLE_WP_CRON', true);
This blocks wp-cron from running at all, so either one of these solutions should work on their own.
Another option would be to disable wp-cron, but leave the full database syncing in place, and schedule a script to call each site's wp-cron.php (you'd be accomplishing manually what the wp-cron service does automatically). That way, it will only run on the active node and the data should be synced over to the passive node with no problems.
im working on a project, where i want to fetch last minute flights and then save them into my database. The problem is that i don't want scrape everytime the user visits the website and then save into my database because that will only cause alot of duplicates. Can i somehow make the website fetch the data for me on a scheduled time and then delete previous records in the database?
If you want the OS to execute a task periodically, cron job is what you want.
Either get the cron job to call your program via the command line, or use wget to fetch the page that would trigger the data fetching.
More on cron jobs:
http://www.thesitewizard.com/general/set-cron-job.shtml
I need to index 80.000 nodes.
The max amount of nodes I can index per each cron run is 500.
I need to run crone 80.000 / 500 times to index the entire website.
How can I automatically schedule these runs (when a run is finished, the next run automatically should start)?
I don't have SSH access so I cannot use drush.
Thanks
All cron does is visit yoursite.com/cron.php
So you could use cron/schedule task/etc on a local machine.
Did you try Poormanscron?
A module which runs the Drupal cron operation using normal browser/page requests instead of having to set up a crontab to request the cron.php script. The module inserts a small amount of JavaScript on each page of your site that when a certain amount of time has passed since the last cron run, calls an AJAX request to run the cron tasks. Your users should not notice any kind of delay or disruption when viewing your site. However, this approach requires that your site gets regular traffic/visitors in order to trigger the cron request.
Why don't you set a cronjob every 4 minutes or so? Just make sure that the interval between cronjobs is longer than the time it takes to run the cron script, so it won't overlap.
Give a try to Apache Solr Search module in drupal.
To reiterate and clarify other answers: As long as you haven't explicitly blocked it in .htaccess or Apache configuration, you can trigger Drupal's cron.php simply by visiting yoursite.com/cron.php from any browser. You can also set up your local machine (or any other machine that has web access, really) to run its own cronjob which triggers your site's cron.php. This process varies from platform to platform, but for example, on most Linux systems, you could run crontab -e and add a line like this:
0 * * * * wget -O - -q -t 1 http://www.example.com/cron.php
# Run example.com's cron tasks at the beginning of every hour.
or possibly:
*/5 * * * * wget -O - -q -t 1 http://www.example.com/cron.php
# Run example.com's cron tasks at every five minute interval.