M
M
Manuchehr Jalolov2018-07-23 15:45:13
Task Schedulers
Manuchehr Jalolov, 2018-07-23 15:45:13

How to optimize php(CRON) code?

We have a website hosted by TimeWeb and we received messages not long ago

Dear Customer!
Our specialists recorded a high load on the server when executing the script *******/myCron.php.
We were forced to remove the rights to the file, in order for it not to run, please optimize the work of this script to reduce the generated load.

Here is myCron.php script
function cron()
  {
    $url = "https://royal.nurshifo.ru/cron.php";
    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch,CURLOPT_POSTFIELDS,http_build_query(""));
    $res = curl_exec($ch);
    if(curl_error($ch))
      { 
        var_dump(curl_error($ch));
      }
    else
      { 
        return json_decode($res);
      } 
  }
echo "s"; 
for($i=0 ; $i<20 ; $i++){
cron();
sleep(3);
}

The question is the same, how can this script be optimized!? The court is that cron.php would work every 2 seconds and we created a cron task for every minute in myCron and delayed the script there for 60 seconds

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Aksentiev, 2018-07-23
@kinglostov

Take the UPU, and no one will write such messages.
this script does not look like some problematic one, it just constantly hangs in work, maybe that's why they don't like it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question