R
R
Rxd2015-07-03 16:49:18
PHP
Rxd, 2015-07-03 16:49:18

How to implement recursive launch of PHP on hosting?

There is a hosting where max_execution_time = 30, exec and system are disabled. It is necessary to parse about 200-300 pages, while the script must be called by cron after a certain time. I decided to do it through recursion, something like

$var1 = $_GET["var1"];
... 
curl_setopt($ch, CURLOPT_URL,"http://domain.com/myphp.php?var1="....);
curl_exec($ch);

But the problem is that all executed scripts remain "hanging", waiting for a response, which greatly slows down the whole process, and it doesn't give more than 5 scripts... How to configure curls so that they don't wait for a response? Or maybe there are some more practical alternatives?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Viktor Savchenko, 2015-07-03
@Rxd

It will be much easier to change hosting or buy VDS, which is the most popular now. Otherwise, after solving the problem with 30 seconds, you will begin to "shake" for the load.
I offer my services in England: UAPEER Hosting Solutions

D
Dark_Dante, 2015-07-03
@Dark_Dante

Did it once through sockets that call the script itself

public function exec_script($url, $params = array()){
    $parts = parse_url($url);
   
    if (!$fp = fsockopen($parts['host'], isset($parts['port']) ? $parts['port'] : 80))
    {
      return false;
    }
   
    $data = http_build_query($params, '', '&');
   
    fwrite($fp, "POST " . (!empty($parts['path']) ? $parts['path'] : '/') . " HTTP/1.1\r\n");
    fwrite($fp, "Host: " . $parts['host'] . "\r\n");
    fwrite($fp, "Content-Type: application/x-www-form-urlencoded\r\n");
    fwrite($fp, "Content-Length: " . strlen($data) . "\r\n");
    fwrite($fp, "Connection: Close\r\n\r\n");
    fwrite($fp, $data);
    fclose($fp);
   
    return true;
  }

Well, the challenge was
//теперь нам надо чекнуть ссылку на наличие в базе
        $b=$this->checkBase($hash);
        //если в базе такой страницы не существует
        if($b==false){
          $this->exec_script($addcache_url, array('hash'=>$hash, 'href'=>$href, 'parent'=>$content["id"]));
            
          
        }

E
entermix, 2015-07-03
@entermix

You can parse in batches, i.e. several pages per run

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question