I've had an issue with this piece of script for a month now http://pastebin.com/f6LqgqQS. What the script is supposed to do is loop through all my posts, pull the like count from the facebook graph and update the post's meta with it.

Now the issue I've had for so long is that not all of my posts were updated. It worked fine when I had 5 posts or so but once I reached 60+, the older posts were left unaffected. They did update after a while though, but it could take over 4 days even though wp_cron is set to hourly (and I know it needs visitors to run).

Now I always thought that graph api was the culprit and that facebook limited my number of requests, but after some testing with running the script on init instead, it seems that wp_cron was causing the problem. I even disabled wp_cron now and I'm running it from the Cpanel with cronjob and so far it has worked great.

But the problem right now is that I don't really have a way to confirm that the script does indeed work correctly and if wp_cron was the culprit after all, as my searches turned up nothing. So I'm wondering if someone more experienced here could take a look at the script and figure out if indeed wp_cron was the problem after all.

1 Answer 1


The wp-cron process runs as a web request. PHP processes run from the web typically have a limit to their run time, like 60 seconds or so. Processes run as a command line process (like from a real cron) have no such limit.

So the problem here is that the script takes too long to run and gets killed. There is no fix for this, wp-cron is not intended to do long-running custom scripts.

And if you keep hitting facebook's Graph API 60 times an hour, they'll eventually block you. Scale it back, you should only get this information once a day, at most.

Better yet, write the script so that it only updates info for those posts when they are actually accessed in the last day or so, and just uses the cached info the rest of the time.

  • Thanks, that explains a lot. And I understand the risk with facebook's Graph API. I'll try to look into FB.Event.subscribe and only run the script for those posts that are clicked. And I guess a Batch Request would solve that too.
    – Tony Fire
    Jan 29, 2014 at 11:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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