-2

i have vps and need some help with case , in crontab there are command run every minute

* * * * * /usr/share/html/mysite/do.php

in do.php file there are some thing like this

<?php
    class job
    {   
        function fetch()
        {
            global $curl;

            for($i=0;$i<4;$i++) {
                $res = $curl->get('http://www.****.com/data.php');
                if($res == 'OK') {
                    return 'OK';
                }
                sleep(60);  
            }
        }       
    }   
    $job = new job();

    $value = 5;
    for($i=0;$i<$value;$i++) {  
        $job->fetch();  
    }
?>

now my problem in$job->fetch(); i want Repeat five times with out wait but my problem its wait respond from function fetch maybe 1 min or max 4 min i need to run this job 5 times in same . note: i can use any thing curl exec etc...

Miro
  • 1
  • 2

1 Answers1

0

You can't run 5 functions at the same time in php, it's a synchrone language and monothreaded(can be tweeked with libraries How can one use multi threading in PHP applications . If your function fetch take 1 minute to run you have to wait 1 minute before the next turn of the loop and the next call to fetch.

  • how ti install in centos php 7 ? – Miro Jul 26 '18 at 16:17
  • You really need to explain your issue better to except better answers. I d'ont understand what you want to achieve here, run 5 time fetch in parallel, or make the function fetch run faster ? – Valentin Bensamon Jul 27 '18 at 08:47