• Resolved SVTX

    (@12ax7)


    Hello there,

    I am trying to set up an hourly cron job. It’s set to execute wp-cron.php once every hour. My hosting company’s support told me to add a “shebang” to the wp-cron.php file:

    #!/usr/bin/php5.4

    Now, I am wondering if that line (1st line) will be overwritten in WP updates?

    I’ve disabled wp-cron in wp-cofig-php:
    define(‘DISABLE_WP_CRON’, true);

Viewing 9 replies - 1 through 9 (of 9 total)
  • Yes, if an update included the wp-cron.php file, it would be overwritten.

    I always disable wp-cron.php in my wp-config.php and just run the cron job like this:

    /usr/bin/php -q /home/username/public_html/wp-cron.php >/dev/null 2>&1

    You’re telling cron to use php at the beginning of the cron job, so no shebang needed.

    It looks like for your server you would replace the /usr/bin/php I use with /usr/bin/php5.4. You’ll also need to adjust the path so it matches your file structure, but it should work if you’re on a Linux server.

    Thread Starter SVTX

    (@12ax7)

    Hello linux4me2,

    that sounds ideal but unfortunately I don’t have root access on my server.

    Could I instead clone wp-cron.php and have the new file deal with it? Say, wp-cron2.php?

    I’m a makeup artist by nature so this stuff really twists my mind.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    You don’t need root access on your server. That’s just the command you will use for the cron job you’re setting up.

    Thread Starter SVTX

    (@12ax7)

    So I would do this:

    /usr/bin/php5.4 -q www/wp-cron.php >/dev/null 2>&1

    (Because she tells me in Admin that my path is supposed to begin right there)

    Jesus, I’m such a nooby twat ??

    Thread Starter SVTX

    (@12ax7)

    Unfortunately that’s not working.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    You would most likely want to put the full path to the PHP file, not “www/wp-cron.php”. Cron jobs don’t necessarily run with your full environment.

    Thread Starter SVTX

    (@12ax7)

    No the path is correct, it worked without the shebang string before and it works without it again, they specifically mentioned to start from that directory. That’s why I’m wondering if I may not be able to define the shebang from there. I’ve submitted a support ticket with my hosting company to make sure this is actually technically possible. Thanks for your help man, I really want to send this boat on its way.

    Thread Starter SVTX

    (@12ax7)

    Support suggested a wrapper script:


    #!/bin/sh
    wget -O – -q https://www.domain.com/wp-cron.php > /dev/null
    exit 0

    Seems to be working fine and it’s update proof.

    Thread Starter SVTX

    (@12ax7)

    For people who want to do this.

    Add the above code (without the —‘s) to a text file and save it as wp-cron.sh, upload to your server, make it executable (CHMOD) by the server and point your cron job towards it. Disable wp-cron in wp-config and install the Crontrol Plugin to check if the crons are being run.

    This was fun to learn, thanks to everyone who helped!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Real Cron Job, Shebang, edit wp-cron.php, Update safe?’ is closed to new replies.