/**
  * tests that you can add a curl handle during a callback
  */
 public function testAddCurlHandleInCallback()
 {
     $this->_callbacks = 0;
     $this->_curl_multi = new Curl_Multi();
     $this->_curl_multi->addHandle(curl_init('http://www.iana.org/'), array($this, '_curl_callback_test_add_curl_handle'), $this);
     // finish always returns true.
     $this->assertTrue($this->_curl_multi->finish());
     // make sure we got two requests back.
     $this->assertEquals(2, $this->_callbacks, "Can add another request inside an existing request callback");
 }
Exemple #2
0
<?php

/* This example was tested on PHP 5.3.2 */
require "Curl/Multi.php";
$curl_multi = new Curl_Multi();
$ch1 = curl_init("http://www.example.com/");
$ch2 = curl_init("http://www.example.com/");
$callback = function ($curl_info, $curl_data, $callback_data) {
    echo "CALLBACK DATA: {$callback_data}\n";
    echo "CURL_INFO:\n";
    print_r($curl_info);
    echo $curl_data;
};
$curl_multi->addHandle($ch1, $callback, "Handle 1");
$curl_multi->addHandle($ch2, $callback, "Handle 2");
/*
   optionally you can process other stuff while waiting for HTTP requests to come back...

   while ($not_done_processing_other_stuff)
   {
   		$not_done_processing_other_stuff = process_more_async_stuff();
		$curl_multi->poll();
	}
*/
$curl_multi->finish();