Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP] multi curl, curl_multi_select zawsze zwraca wartosc -1
Octobus
post 4.07.2018, 09:55:08
Post #1





Grupa: Zarejestrowani
Postów: 259
Pomógł: 1
Dołączył: 3.07.2011

Ostrzeżenie: (0%)
-----


Cos zmienili mi na serwerze i multicurl zaczal mi zwracac zawsze przy curl_multi_select wartosc -1 (oczekuje na wykonanie). Przykladowy kod przeklejony z manuala


Kod
// create both cURL resources
$ch1 = curl_init();
$ch2 = curl_init();

// set URL and other appropriate options
curl_setopt($ch1, CURLOPT_URL, "https://www.google.pl/");
curl_setopt($ch1, CURLOPT_HEADER, 0);
curl_setopt($ch2, CURLOPT_URL, "http://www.php.net/");
curl_setopt($ch2, CURLOPT_HEADER, 0);

//create the multiple cURL handle
$mh = curl_multi_init();

//add the two handles
curl_multi_add_handle($mh,$ch1);
curl_multi_add_handle($mh,$ch2);

$active = null;
//execute the handles
do {
    $mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);

while ($active && $mrc == CURLM_OK) {
    if (curl_multi_select($mh) != -1) {
        do {
            $mrc = curl_multi_exec($mh, $active);
        } while ($mrc == CURLM_CALL_MULTI_PERFORM);
    }else{
        echo '.';
        sleep(1);
    }
}

//close the handles
curl_multi_remove_handle($mh, $ch1);
curl_multi_remove_handle($mh, $ch2);
curl_multi_close($mh);


caly czas zwraca mi ... i nigdy nie dochodzi do konca. curl_multi_select($mh) zawsze zwraca -1. To jest przykladowy kod, moj jest bardziej rozbudowany i sprawdza url'e ktore na pewno dzialaja ale zawsze jest ten sam status ...

Ten post edytował Octobus 4.07.2018, 09:55:45
Go to the top of the page
+Quote Post
Pyton_000
post 4.07.2018, 13:01:52
Post #2





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

Ostrzeżenie: (0%)
-----


  1. while ($active && $mrc == CURLM_OK) {
  2. if (curl_multi_select($mh) != -1) {
  3. echo '.';
  4. sleep(1);
  5. }
  6. do {
  7. $mrc = curl_multi_exec($mh, $active);
  8. } while ($mrc == CURLM_CALL_MULTI_PERFORM);
  9. }

o tak zobacz
Go to the top of the page
+Quote Post
Octobus
post 5.07.2018, 10:27:29
Post #3





Grupa: Zarejestrowani
Postów: 259
Pomógł: 1
Dołączył: 3.07.2011

Ostrzeżenie: (0%)
-----


Gdyby komus sie przydalo, ponizej zamieszczam przykladowy kod ktory dziala i odbiera zawartosci pliku. Jakby ktos widzial bledy, bede bardzo wdzieczny za sugestie
Kod
while ($active && $mrc == CURLM_OK) {
    curl_multi_select($mh);
    
    do {
        $mrc = curl_multi_exec($mh, $active);
    } while ($mrc == CURLM_CALL_MULTI_PERFORM);
    
    if ($mhinfo = curl_multi_info_read($mh)) {
        $response = curl_multi_getcontent($mhinfo['handle']);
        echo PHP_EOL.'Zawartosc watku: '.$response.'####';
    }
}
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 28.03.2024 - 15:01