I write the wordpress plugin . That Contains curl code...

When I open wordpress site Ex(http://localhost/wordpress or http://localhost/wordpress/wp-admin ,...) this plugin running. But I Want Run this Plugin every day no ever open the url..

I use cron_schedules function but But the problem is not resolved..

This part of the code

$ch = curl_init ("http://widgets.farsnews.com/currency/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US;         rv: Gecko/20080311 Firefox/');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
$page = curl_exec($ch);

$dom = new DOMDocument('1.0', 'utf-8');
$xpath = new DOMXpath($dom);
| improve this question | | | | |

As you mentioned, WordPress by default only runs the wp_cron when the WordPress site is visited. This of course will cause problems if you are needing to schedule some event reliably, and you aren't getting consistent traffic to your site.

To resolve this, you can disable the default functionality of the wordpress cron by adding the following line to your wp-config.php file:

define('DISABLE_WP_CRON', true);

After the default cron is disabled, you can then add a normal Unix Cron on your machine (your webhost or your local computer, whichever environment you are running this site on) to load the wp-cron.php for your domain on a regular interval. You would add a cron with something like this (replacing the domain with your own):

/15 * * * wget -q -O – http://yourdomain.com/wp-cron.php?doing_wp_cron

This will cause your WordPress site to run the cron every 15 minutes, independent of traffic loading your page.

How to set up a Linux/Unix Cron:

How to set up a Cron with cPanel or Plesk:

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.