Alternative cron script if HTTP/Request.php isn't available

1 year 11 months ago #1 by Trevor
Hi

I was having a problem running the cron script on my server. The problem was caused because HTTP/Request.php was not installed on any of the hosting company servers. So I hacked the script to use cURL instead (see below).

regards
Trevor
<?php

$sites_array = array();
$sites_array[] = 'http://yoursitehere.com';
// you need to write it exactly as you write it to get the Cron Job Key
// Cron Job key is the md5 below:
// md5('NS Pro Bounce Key For: ' . $site)
// Example: The md5 of "NS Pro Bounce Key For: http://localhost/tester364" is cdc5eaa1b9e6e1fa0e4b90fa74b898f3

$resultstring = '';
if (function_exists('http_build_query')) {
  $handle = curl_init();

  foreach($sites_array as $site) {
    $bkey = md5('NS Pro Bounce Key For: ' . $site);
    $url = $site.'/index.php?option=com_nspro&task=docronjobs';
    $postData = ['extensionid' => 'NSPRO1#', 'validationid' => $bkey];
    
    curl_setopt_array($handle,
    array(
        CURLOPT_URL => $url,
        CURLOPT_POST   => true,
        CURLOPT_POSTFIELDS => $postData,
        CURLOPT_RETURNTRANSFER => true,
        )
    );

    $page = curl_exec($handle);
    $resultstring .= 'Checking website: ' . $site . "\n" . 'Key produced: ' . $bkey . "\n". 'Result: ' . $page . "\n\n";
  }
  if (!file_exists('cronresults')) { mkdir('cronresults'); }
  $file = fopen('cronresults/cronresult' . date('Y-m-d') . '.txt', "a");
  fwrite($file, $resultstring);
  fclose($file);
}
?><!DOCTYPE html>
<head>
<meta charset="utf-8"/>
<title>NS Pro Cron Job Results</title>
<style type="text/css">
  .pre { background-color: #F9F9F9; border: 1px solid #D5D5D5; }
</style>
</head>
<body>
<h1>NS Pro Cron Job Results</h1>
<p>Results: </p>
<pre><?php print $resultstring; ?></pre>
</body>
</html>

Please Log in or Create an account to join the conversation.

1 year 11 months ago #2 by Christopher Mavros
Replied by Christopher Mavros on topic Alternative cron script if HTTP/Request.php isn't available
Hello Trevor and thank you very much for your post!
I haven't tested it yet, but I believe it should be ok.

Thanks again!

Christopher Mavros
mavrosxristoforos@gmail.com
If you like our extensions, please rate us on the JED!

Please Log in or Create an account to join the conversation.

Moderators: Christopher Mavros