Calling Snapshot from a server cron job?

Is there a way to call Snapshot from a server cron job?

Some of our sites are on shared hosting which does not support http loopback, therefore WP-Cron doesn't work.

  • LimeCanvas
    • Flash Drive

    Hi Paul,

    Thanks for the reply.

    The problem with setting up a generic cron job for a WP site is that it will fire the cron and process everything it can at that particular interval.

    On our shared systems I have a crontab call to wp-cron every 15 min however cron being as tempermental as it is, there's still no guarantee that it will fire.

    Would it be possible to add a direct crontab call via PHP, Curl or WGET for snapshot as a future feature request?

    That way administrators could setup a nice crontab which is realiable and offload the process from wp cron.

    Cheerz

  • Paul
    • The Green Incsub

    @LimeCanvas, I would need to think on it. Would not be too hard. But I'm deep on some other Snapshot features this week. So really don't want to start thinking on ths and get distracted. For now let's turn this into a feature request and get some votes from others.

  • David
    • The Crimson Coder

    I'm far from a wget guru, but I think you can also use:

    wget -q --delete-after

    As a way to make sure the wget doesn't save an html file and does it quietly. The redirection in the command listed above does similar things, but I think -q saves some cycles.

  • Paul
    • The Green Incsub

    @David, Thanks. I started thinking about this since my original post. I'm thinking wget is not a good solution for crontab. Best to just call a php file direct. I'll add some thoughts here later in the week once I get past some other development hurdle.

  • Paul
    • The Green Incsub

    @LimeCanvas, Ok. Got something for you. I've put together a file snapshot-cron.php that is in the snapshot plugins directory. Because these changes needed also some changes to Snapshot I've packages this up as a beta zip file. See link below.

    https://dl.dropbox.com/u/2616987/WPMUDev/snapshot-2.1.1-Beta7.zip

    The snapshot-cron.php is somewhat documented. You basically need to setup the cron to call the script and pass in a few arguments. I've given example in the top of the snapshot-cron.php script.

    Let me know if you run into any issues.

  • LimeCanvas
    • Flash Drive

    Hi Paul,

    I kicked off a Cron but it doesn't seem to be completing the snapshot using the cron url:

    /usr/bin/php /home/sites/**REDACTED**.com/public_html/wp-content/plugins/snapshot-2.1.1-Beta7/snapshot-cron.php WP_SITE_DIR=/home/sites/**REDACTED**.com/public_html WP_SITE_NAME=www.**REDACTED**.com SNAPSHOT_ITEM=1354843579

    I double checked that the snapshot item was correct from the admin url:
    /wp-admin/admin.php?page=snapshots_edit_panel&snapshot-action=edit&item=1354843579

    There are some errors in the log file. Here's a sample:
    2012-12-07 01:29:55: Notice: errno:8 Undefined variable: description /home/sites/**REDACTED**.com/public_html/wp-content/plugins/social-networks-auto-poster-facebook-twitter-g/NextScripts_SNAP.php on line 671

    Also in the server error log is the following, although I think that's more a UI issue and nothing to do with the cron job:
    [Fri Dec 07 02:01:23 2012] [error] [client **REDACTED**] PHP Warning: json_encode() [function.json-encode]: Invalid UTF-8 sequence in argument in /home/sites/**REDACTED**.com/public_html/wp-content/plugins/snapshot-2.1.1-Beta7/snapshot.php on line 5468, referer: http://www.**REDACTED**.com/wp-admin/admin.php?page=snapshots_edit_panel

    If you email me at wil@limecanvas.com I can send you copy of the full log.

    Cheerz,
    Wil.

  • Paul
    • The Green Incsub

    @LimeCanvas, Hmm. Can you first just try running from the command line. I was testing on my server one directory level above the root (not that it should matter).

    The first log entry is probably normal. Either way it is not from Snapshot. But probably caused when Snapshot initialized WP.

    The second log item is Snapshot from this is not from the cron process. Looks like it from the web interface. Note the URL part admin/admin.php?page=snapshots_edit_panel tells me this is the snapshot page.

    I'll email you direct.

  • Paul
    • The Green Incsub

    @FourLeafed,

    No. And there probably will not be one. You have two choice. Use the WPCron system as it was designed. Or you can setup a true UNIX crontab to call the WordPress wp-cron.php directly. There is not an option to call Snapshot directly.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.