Jump to content

how can I make cron run a job right now, for testing/debugging? without changing the schedule!


Recommended Posts

Hello there

Sometimes if my crons fails due to php mismatch or whatever issues with website, and, to avoid waiting more 24 hours, after a fix, I would usually change it manually on WHMCS Setup> automation settings  to next hour, according to currently time.

image.png.1b4296df1fc89539a784b01a29bff818.png

How to make crons RUN now, to execute send invoices, reminder, etc etc.?

Link to comment
Share on other sites

1 hour ago, brian! said:

you can run it from the browser, or via the server command line...

😬 I am afraid that my cron is not in public_html directory, so I guess first option web-browser is not possible!!

1 hour ago, brian! said:

or via the server command line...

😣 also I think SSH is not available on my cpanel

Link to comment
Share on other sites

I have overpass this issue.

But I guess running cron from website http://www.yourdomain.com/whmcs/crons/cron.php does not start automatically backup with that command ( I mean, creating a full cpanel backup and send it via SCP or FTP to other desired location).

I am restructuring my backups setting, so  I need to test it after implementing and not waiting 24 hours to see if it work. How can I enforce auto-backup process if this way do not work?

Link to comment
Share on other sites

I use the following hook to run cron jobs whenever I want on my dev systems. It automatically adds a button on top of your WHMCS (the organge one in the screenshot below). When you press it...

  • The "Cron last run" resets so you can run it multiple times per day
  • The "Time of Day" is autoimatically set to current hour
  • The cron runs via curl()

whmcs-live-demo.png.4481891255465dbe1aa9b51869c55d74.png

Keep in mind that I'm just copy/pasting my script that assumes cron.php is in ROOT/crons directory. As I said earlier, I use it on dev installations of WHMCS where I don't need to move crons directory. You surely need to change it so that it can run your cron.php file that is above "www".

<?php

/**
 * Add button to run WHMCS Daily Cron Job on click
 *
 * @package     WHMCS
 * @author      Kian
 */

use WHMCS\Database\Capsule;

add_hook('AdminAreaHeaderOutput', 1, function($vars)
{
    // Simulazione Cron
    if ($_GET['simulatecron'])
    {
        $SystemURL = Capsule::table('tblconfiguration')->where('setting', 'SystemURL')->first(['value'])->value;
        Capsule::table('tblconfiguration')->where('setting', 'lastDailyCronInvocationTime')->update(['value' => '']);
        Capsule::table('tblconfiguration')->where('setting', 'DailyCronExecutionHour')->update(['value' => date('H')]);

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $SystemURL . 'crons/cron.php');
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        $output = curl_exec($ch);
        curl_close($ch);
    }

    $output = <<<HTML
<style>
.katademo1 { color:#fff !important; background-color:#eaae53 !important;}
</style>
<script type="text/javascript">
$(document).on('ready', function(){
    $('body>.topbar>.pull-left').append('<a href="index.php?simulatecron=1" title="Each press simulates the Daily Cron of WHMCS" class="update-now katademo1" id="simulatingcronjob">Run Daily CronJob <i class="fa"></i></a>');

    $("#simulatingcronjob").on('click', function(e){
        if (confirm('Simulating the Cron Job might take a few minutes. Please be patient.'))
        {
            $(e.currentTarget).find('.fa').addClass('fa-pulse fa-spinner');
        }
		else
		{
			e.preventDefault();
		}
    });
});
</script>
HTML;

    return $output;
});

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated