Hot answers tagged wp-cron
9
The answer is apparently YES, I should worry. After some research, I've found that the warning seems to be related to misconfigurations on the server that WordPress is hosted on (ie. a problem with my server, not WordPress).
Common misconfigurations:
Server doesn't have DNS, and so it can't figure out who "example.com" is, even though it is itself.
Server ...
8
After some testing indeed, both WP Super Cache and W3 Total Cache do not release the buffer (or prevent the buffer from being released).
Turning off "output delay" is simple and depends on the caching plugin involved.
WP Super Cache:
wp_cache_disable();
ob_end_flush(); // or ob_end_clean();
This should be added after including wp-load.php, this stops ...
7
My favorite plugin for that is Core Control which has very nice module for display of what is going in the cron - which events are set up, when are they next firing, etc.
On getting your hands dirty level see _get_cron_array(), which returns internal stored data for cron events (top level of keys are timestamps).
6
Neither.
register_activation_hook( __FILE__, 'trigger_me' );
function trigger_me() {
if ( !wp_next_scheduled( 'my_plugin_cron' ) ) {
wp_schedule_event(time(), 'hourly', 'my_plugin_cron');
}
}
Why parse code on every request when you don't need to?
5
Check out wp_cron and the cron_schedules filter. There are lots of good tutorials out there like this one from WPTuts or this one from Viper007Bond.
5
Thanks to Rarst this makes a hell of a lot more sense now. So I've updated this post to elaborate the differences Rarst mentioned and upvoted his for shedding light on this ; )
Basically wp_schedule_single_event passes the arguments to your function through the variable args as shown in the codex. This variable "args" must be an array because each value in ...
5
WordPress lets you add custom cron schedules, which is normally what you'd want to do in this situation, in conjunction with wp_schedule_event(). But, they work based on intervals rather than specific dates/times. For instance,
add_filter( 'cron_schedules', 'addCustomCronIntervals' );
function addCustomCronIntervals( $schedules )
{
$schedules[ ...
5
Edit: wp_next_scheduled() returns the timestamp of the next scheduled job of a specified wp-cron job-arguments pair.
Please note that this differs slightly in functionality to the answer below, in that you have to provide the arguments passed to cron job's callback (if it has any). The original answer would provide the time of the next specified job ...
5
Firstly, define your custom cron job schedules.
add_filter('cron_schedules', array($this, 'cron_schedules'));
public function cron_schedules($schedules){
$prefix = 'cron_';// Avoid conflict with other crons. Example Reference: cron_30_mins
$schedule_options = array(
'30_mins' => array(
'display' => '30 Minutes',
...
4
It looks for me that you are adding this event only when there is no such event 'send_email_alerts_hook' scheduled yet. Try something like this and let me know if it workded.
function shedule_email_alerts() {
if ( !wp_next_scheduled( 'send_email_alerts_hook' ) ) {
wp_schedule_event(time(), 'daily', 'send_email_alerts_hook');
} else {
...
4
This is only a partial answer. You can use Cron View to see what crons are still active on your blog.
If you find some crons that shouldn't be there then maybe my answer here will help you remove that cron: Cron jobs for deactivated plugins
4
I think you have mismatch in how you pass arguments and how you expect it to work. You pass array of arguments to schedule and expect your hooked function to receive identical array of arguments. This is not the case.
Cron events are processed by do_action_ref_array(), which in turn passes arguments via call_user_func_array().
So your hooked function does ...
4
Disable any plugins you may have that do whole-page caching. WP-Super-Cache, W3 Total Cache, etc.
WordPress does not "delay output". But whole page caching plugins usually do. This is because they are trying to get that output and save it somewhere, for later usage in serving the page. Thus, the page output is delayed until the end, where the plugin can ...
4
As you've noted, cron jobs are only fired when someone visits your website. WordPress checks if they are any events that have been scheduled before 'now' that have not yet occurred - and runs them.
Importantly with events that are recur according to a regularly pattern (say hourly) - their occurrence is relative not absolute. That is, once your event ...
4
Whenever you do get_posts or WP_Query or anything like that, it's important to remember that the code is actually getting all of the Posts at once, and loading them from the database into memory. If you run out of memory, then your process will simply die with an error. Attempting to get very large numbers of posts at once will cause this quite often.
Turn ...
3
Basically every page load looks to see if there is anything scheduled to run, so by that logic the cron is checked and can possibly run on every page load.
I can only presume you want to schedule something to run every so often. If that's the case you need to look at wp_schedule_event()
Below is the code to get some code to run ever hour:
...
3
Yes, the event will trigger when the wp-cron process gets run. If something is preventing wp-cron from running, then it won't trigger at all. If you're having it not work, then something about your server configuration is preventing it from working.
For these cases, you can generally work around them by adding this define to your wp-config file:
...
3
Where are you putting the wp_schedule_event() code? My guess is, you have it somewhere that's causing it to run on every page load, causing the action to be scheduled multiple times (like maybe you just dropped it in your functions.php?).
You only need to schedule the action once. The easiest way is to do it on activation of your plugin. Try something like:
...
3
You can do this via wp_cron by using the following,
function more_reccurences() {
return array(
'sixhourly' => array('interval' => 21600, 'display' => 'Every 6 hours'),
);
}
add_filter('cron_schedules', 'more_reccurences');
then find the function that does the autopost and call it by
if ( !wp_next_scheduled('autopost_function') ) {
...
3
I do not think it is useful to have a cron running every second, but the function itself is quite simple.
You add a filter to the cron_schedules:
function f711_add_seconds( $schedules ) {
$schedules['everysecond'] = array(
'interval' => 1,
'display' => __('Every Second')
);
return $schedules;
}
add_filter( ...
3
First can you please confirm that you don't have any caching plugins enabled? Caching plugins can interfere with cron jobs because your visitors are not served a live page but a cached version of your page.
If you have a caching plugin enabled, you can choose one of your pages, add an exclussion to your caching plugin's settings for that page so that it is ...
2
create for these posts a customfield with the name expires and the value is the date for disabling the post.
Use the following code in the Loop of your theme.
//Loop-Start
if (have_posts()) : while (have_posts()) : the_post();
$exTime = get_post_custom_values('expires');
if (is_array($exTime)) {
$exString= implode($exTime);
$seconds = ...
2
Although both of your options (that is, using transients or using a cron job) are viable, I'm a fan of using transients unless the dataset is exceptionally large or if there is some need to automate the process.
Without seeing much of your current code, it's difficult to give a working example. Nonetheless, if you end up going the route of transients, I'd ...
2
After this remark from the OP:
To be clearer, I have scheduled posts in the future, and I want the cache to clear when the are published via the wp-cron trigger. There might be a better way?
I do not know if the W3 Total Cache plug-in not automatically flushes the cache when posts are published. I believed it did. If it does not - then in this intance ...
2
The cron event needs to be registered on the plugin activation hook like so:
register_activation_hook( __FILE__, 'activate_cron' );
function activate_cron() {
wp_schedule_event( current_time( 'timestamp' ), 'hourly', 'the_function_to_run' );
}
The the_function_to_run defined in the wp_schedule_event needs to be your function that you want to run at ...
2
Yes.
No, because the scheduled job hasn't reached the time yet.
Yes, but not until 7:03pm.
Basically, any hit to the site after the scheduled time will cause the queued job to run. The WP_Cron is a "best effort" system, not an exact timer. This is generally good enough though, since if nobody's visiting the site, then it doesn't need to run and do ...
2
You could use WordPress' pseudo-cron and wp_schedule_single_event.
<?php
// add the action.
add_action('wpse71941_cron', 'wpse71941_long_running');
function wpse71941_long_running($args)
{
// might need to call `set_time_limit` here
set_time_limit(0);
// do long running stuff here
// return normal time limit
if($l = ...
2
WordPress Cron allows you to schedule tasks, but they will only execute if there is a request made to the site. For each request that WordPress receives it will check to see if there are cron jobs to process, and if so fires off a request to /wp-cron.php?doing_wp_cron asynchronously to process the job. If a job's scheduled start passes without a request, ...
2
I believe by default these folders are created by user interaction, however, it's possible that a plugin may be calling a function to create these monthly upload folders.
Note that using this function will create a subfolder in your Uploads folder corresponding to the queried month (or current month, if no $time argument is provided), if that folder is ...
2
This is the intended use of the WP_CRON_LOCK_TIMEOUT constant.
When WordPress is loaded, it checks to see if a cron job is running (if cron is locked). If cron is not locked, it will try to create a lock - if the lock timeout has not been reached, no lock can be acquired and cron is not run.
If no cron job is running, and the timeout has passed (meaning a ...
Only top voted, non community-wiki answers of a minimum length are eligible
