Nedeniyle uzun bekleme Kıvrılmaları Alternatif

4 Cevap php

Hey Guys I currently run a PHP-script using CURL to send data to another server, to do run a PHP-script that could take up to a minute to run. This server doesn't give any data back. But the CURL-request still has to wait for it to complete, and then it loads the rest of the orignal page. I would like my PHP-script to just send the data to the other server and then not wait for an answer.

Yani benim soru nasıl bu çözmek gerekir? Ben CURL her zaman beklemek zorunda olduğunu okudum. Sizin önerileriniz nelerdir?

Thank You!

4 Cevap

Bu yararlı bir başlangıç ​​noktası olabilir, flagrantly copypasted from here olabilir

function curl_post_async($url, $params)
{
    foreach ($params as $key => &$val) {
      if (is_array($val)) $val = implode(',', $val);
        $post_params[] = $key.'='.urlencode($val);
    }
    $post_string = implode('&', $post_params);

    $parts=parse_url($url);

    $fp = fsockopen($parts['host'], 
        isset($parts['port'])?$parts['port']:80, 
        $errno, $errstr, 30);

    //pete_assert(($fp!=0), "Couldn't open a socket to ".$url." (".$errstr.")");(optional)

    $out = "POST ".$parts['path']." HTTP/1.1\r\n";
    $out.= "Host: ".$parts['host']."\r\n";
    $out.= "Content-Type: application/x-www-form-urlencoded\r\n";
    $out.= "Content-Length: ".strlen($post_string)."\r\n";
    $out.= "Connection: Close\r\n\r\n";
    if (isset($post_string)) $out.= $post_string;

    fwrite($fp, $out);
    fclose($fp);
}

http://php.net/manual/en/function.fsockopen.php


$fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);
if (!$fp) {
    echo "$errstr ($errno)
\n"; } else { $out = "GET / HTTP/1.1\r\n"; $out .= "Host: www.example.com\r\n"; $out .= "Connection: Close\r\n\r\n"; fwrite($fp, $out); while (!feof($fp)) { echo fgets($fp, 128); } fclose($fp); }

Eğer PHP web sayfası bağlayan başka bir makinede bir sunucu soketi oluşturabilirsiniz. Bu şekilde, protokol karar. Aksi takdirde, bir arka plan işlemi ihtiyaçlarını karşılayan görmek için sabırsızlanıyoruz.

Ben komut süre sonra çalışmayı durduracak böylece php maksimum yürütme zamanı ayarlayabilirsiniz düşünüyorum. Bu bir "pro" çözüm değil ama işe yarıyor!