Performance and Multisite help — book a call with me via my Expert page on Clarity, I use this service for calls.

WordPress Multisite Cron for high-loaded networks

36 responses to “WordPress Multisite Cron for high-loaded networks”

  1. Larry Levenson Avatar

    Sabrina, excellent post! Very detailed and understandable.

    One thing that wasn’t clear to me. . .
    Looking at “Multisite: better approach,” is that code publishing any post scheduled for today or is it publishing ALL drafts? Obviously, I would like it to publish only today’s scheduled posts.

    Thanks!

    1. SZ Avatar
      SZ

      Hello, Larry!
      This approach may suit your project if you don’t care which particular posts will be published today and which tomorrow but need just to be sure the certain amount (50 in the example above) will be published for sure. Check this line: “First of all we need the very function that will actually publish 50 drafts…” This function will take 50 random drafts from your site and publish them.

  2. Larry Levenson Avatar

    Sabrina, excellent post! Very detailed and understandable.

    One thing that wasn’t clear to me. . .
    Looking at “Multisite: better approach,” is that code publishing any post scheduled for today or is it publishing ALL drafts? Obviously, I would like it to publish only today’s scheduled posts.

    Thanks!

    1. SZ Avatar
      SZ

      Hello, Larry!
      This approach may suit your project if you don’t care which particular posts will be published today and which tomorrow but need just to be sure the certain amount (50 in the example above) will be published for sure. Check this line: “First of all we need the very function that will actually publish 50 drafts…” This function will take 50 random drafts from your site and publish them.

  3. Greg Avatar
    Greg

    Hey Sabrina,

    I appreciate this piece. Thank you.

    Is this a typo/mistake https://www.screencast.com/t/TecmVEBS ?

    I do not see why the final code would have /publishing.php I thought it should be /wp-cron.php?doing_wp_cron etc?

    If not, what should be in the publishing.php file?

    Let me know when you are able.

    1. sz Avatar
      sz

      Hi Greg!
      You’re absolutely right. Just corrected this.
      Cheers!

  4. Greg Avatar
    Greg

    Hey Sabrina,

    I appreciate this piece. Thank you.

    Is this a typo/mistake https://www.screencast.com/t/TecmVEBS ?

    I do not see why the final code would have /publishing.php I thought it should be /wp-cron.php?doing_wp_cron etc?

    If not, what should be in the publishing.php file?

    Let me know when you are able.

    1. sz Avatar
      sz

      Hi Greg!
      You’re absolutely right. Just corrected this.
      Cheers!

  5. Aldemar Calazans Filho Avatar
    Aldemar Calazans Filho

    Hi Sabrina.

    I noticed that in the “Entire trigger.php” you put this line of code:
    $command = $site_url.’/publishing.php’;
    instead that:
    $command = $site_url.’/wp-cron.php?doing_wp_cron’;

    And, telling about “Now we need this publishing.php” you put:
    $command = $site_url.’/wp-cron.php?doing_wp_cron’;
    instead:
    $command = $site_url.’/publishing.php’;

    In other words: you changed the order of the two alternatives, in your examples!

    1. sz Avatar
      sz

      Hi Aldemar Calazans!
      Thank you for pointing this out, I finally corrected this.
      Cheers,
      Sabrina

  6. Aldemar Calazans Filho Avatar
    Aldemar Calazans Filho

    Hi Sabrina.

    I noticed that in the “Entire trigger.php” you put this line of code:
    $command = $site_url.’/publishing.php’;
    instead that:
    $command = $site_url.’/wp-cron.php?doing_wp_cron’;

    And, telling about “Now we need this publishing.php” you put:
    $command = $site_url.’/wp-cron.php?doing_wp_cron’;
    instead:
    $command = $site_url.’/publishing.php’;

    In other words: you changed the order of the two alternatives, in your examples!

    1. sz Avatar
      sz

      Hi Aldemar Calazans!
      Thank you for pointing this out, I finally corrected this.
      Cheers,
      Sabrina

  7. Jake P Avatar

    Thank you for this post, it’s been helpful. Is there a reason why you used wp_remote_get() to hit the php file, rather than just running the php file directly with include/require?

    1. sz Avatar
      sz

      Hi Jake,
      I can’t remember if it was any particular reason for the time of writing to be honest, but you’re right, I believe include directly would be more efficient if it can be used!

  8. Jake P Avatar

    Thank you for this post, it’s been helpful. Is there a reason why you used wp_remote_get() to hit the php file, rather than just running the php file directly with include/require?

    1. sz Avatar
      sz

      Hi Jake,
      I can’t remember if it was any particular reason for the time of writing to be honest, but you’re right, I believe include directly would be more efficient if it can be used!

  9. Stephen Sabatini Avatar

    I had to pass the path to get the correct paths: `get_site_url( $blog_id, $site->path )`. Hope this helps someone.

    1. sz Avatar
      sz

      Thanks for sharing, Stephen! Do you have any idea why you need to do so?

  10. Stephen Sabatini Avatar

    I had to pass the path to get the correct paths: `get_site_url( $blog_id, $site->path )`. Hope this helps someone.

    1. sz Avatar
      sz

      Thanks for sharing, Stephen! Do you have any idea why you need to do so?

  11. Ame. Avatar

    Hello Sabrina,
    Thank you very much for this post. I did all the steps above but I don’t have any cpanel on my webhosting.
    Should I add only one cronjob? My webhosting explanation is like this:
    https://www.combell.com/en/help/kb/programming-recurring-tasks-with-cronjobs/

    1. sz Avatar
      sz

      Hello! And thanks!
      Yeah, I believe if you put trigger.php content into script.php in their example this should work. Also, see another approach with publishing.php below that.
      Cheers!

  12. Ame. Avatar

    Hello Sabrina,
    Thank you very much for this post. I did all the steps above but I don’t have any cpanel on my webhosting.
    Should I add only one cronjob? My webhosting explanation is like this:
    https://www.combell.com/en/help/kb/programming-recurring-tasks-with-cronjobs/

    1. sz Avatar
      sz

      Hello! And thanks!
      Yeah, I believe if you put trigger.php content into script.php in their example this should work. Also, see another approach with publishing.php below that.
      Cheers!

  13. Ame Avatar

    Hello Sabrina,

    I already wrote you, but have an other question. I have a multisite and with two sites on it. I made multisite to have French translation of my main domain. So there is only one domain on the multisite. Example.be/ and example.be/fr
    In my google search console I see no issurs with speed. Do you think that in my situation a multisite could cause a problem for speed?
    With kind regards,
    Amelia

    1. sz Avatar
      sz

      Hi Amelia,
      Site speed in this case would depend on the same things as in any regular installation – which theme do you use, which plugins, how good they perform together.
      Also, make sure to run speed tests for both Example.be/ and example.be/fr separatedely.
      See my SpeedGuard plugin to have site speed monitored (you’ll need to activate on per-site basis)
      Hope this helps.
      Cheers,
      Sabrina

  14. Ame Avatar

    Hello Sabrina,

    I already wrote you, but have an other question. I have a multisite and with two sites on it. I made multisite to have French translation of my main domain. So there is only one domain on the multisite. Example.be/ and example.be/fr
    In my google search console I see no issurs with speed. Do you think that in my situation a multisite could cause a problem for speed?
    With kind regards,
    Amelia

    1. sz Avatar
      sz

      Hi Amelia,
      Site speed in this case would depend on the same things as in any regular installation – which theme do you use, which plugins, how good they perform together.
      Also, make sure to run speed tests for both Example.be/ and example.be/fr separatedely.
      See my SpeedGuard plugin to have site speed monitored (you’ll need to activate on per-site basis)
      Hope this helps.
      Cheers,
      Sabrina

  15. Dave Avatar
    Dave

    Great article – thanks for a detailed approach.

    I’m curious if you have ideas/thoughts on how I could do something like this for a site utilizing Single Sign-On (SSO). Basically, hitting any page on our web server enforces SSO authentication. So, simple http-based cron tasks will fail because the request never makes it to the web server in an authenticated state.

    My multisite instance, which generates ~30k pageviews/week, had wp-cron disabled long before I came along. Figuring out how to implement something manageable that can work around SSO and still trigger wp-cron (maybe server/CLI-based instead of http?) has stumped me.

    1. sz Avatar
      sz

      Thanks, Dave!
      I’m not quite sure I got it right. Do you want to trigger everything but SSO? What would be the perfect outcome?
      Cheers, Sabrina

  16. Dave Avatar
    Dave

    Great article – thanks for a detailed approach.

    I’m curious if you have ideas/thoughts on how I could do something like this for a site utilizing Single Sign-On (SSO). Basically, hitting any page on our web server enforces SSO authentication. So, simple http-based cron tasks will fail because the request never makes it to the web server in an authenticated state.

    My multisite instance, which generates ~30k pageviews/week, had wp-cron disabled long before I came along. Figuring out how to implement something manageable that can work around SSO and still trigger wp-cron (maybe server/CLI-based instead of http?) has stumped me.

    1. sz Avatar
      sz

      Thanks, Dave!
      I’m not quite sure I got it right. Do you want to trigger everything but SSO? What would be the perfect outcome?
      Cheers, Sabrina

  17. Pelton Avatar
    Pelton

    Thank you for this article. Really helpful. I’m using the first example. However when I visit my trigger.php I get the following error:

    “Fatal error: Uncaught Error: Call to undefined function is_multisite()”

    Any idea why?

  18. Laxman Prajapati Avatar
    Laxman Prajapati

    Hello Sabrina,

    Very good the blog is posted,

    I have integrated this code with my website which is running with multisite. But how the WordPress function will work with the trigger.php file? Without the file connect to WordPress? We don’t need to include the wp-load.php file in the trigger.php file? We getting errors so.

    Thanks,
    Laxman P

  19. Laxman Prajapati Avatar
    Laxman Prajapati

    Hello Sabrina,

    Very good the blog is posted,

    I have integrated this code with my website which is running with multisite. But how the WordPress function will work with the trigger.php file? Without the file connect to WordPress? We don’t need to include the wp-load.php file in the trigger.php file? We getting errors so.

    Thanks,
    Laxman P

  20. Ravi Avatar
    Ravi

    Thanks for the script!
    Although the script didn’t work until I had `require_once( dirname( __FILE__ ) . ‘/wp-load.php’ );` as the first line in the file to load all the WordPress functions etc.

Leave a Reply

Your email address will not be published. Required fields are marked *