nasıl (RollingCurl.php yılında) kendi talep url ile ilişkili olduğu tepki verileri bilmek?

1 Cevap php

Ben daha sonra bir dizi içinde saklar (RollingCurl ile) ve end çıkışları o JSON biçiminde anda birden fazla sitelerinden (in parallel) http yanıt başlıklarını kapmak bir web uygulaması yazıyorum.

Since some sites do redirects to new locations, $info (array) in “request_callback” function always contains an url ($info[‘url’]) where the requested url was redirected to, and it’s quite expected. But how to push a requested url into array (@ $info[‘requested_url’]) to know which $info (response data) is associated with its requested url?

$urls = array(
 "http://google.com",
 "http://microsoft.com"
    // more urls here
);

$json = array();
$rc = new RollingCurl("request_callback");
$rc->window_size = 20;

foreach ($urls as $url) {
    $request = new Request($url);
    $rc->add($request);
}

$rc->execute();
echo json_encode($json);
exit;

function request_callback($response, $info) {
       global $json;
       $json['status'][] = $info;
}

Den / / fragmanı RollingCurl.php:

// send the return values to the callback function.
$callback = $this->callback;
if (is_callable($callback)){
    $info[‘requested_url’] = **???** // How to get a requested url & push it into $info?
    call_user_func($callback, $output, $info);
}

1 Cevap

Geri arama işlevi, $ info dizi isteği yapmak için kullanılan curl_multi URL olan bir 'url' anahtar olmalıdır.

O diziye şeylerin listesi için curl_getinfo üzerine php belgelerine bakın.