本文整理匯總了PHP中Curl::success方法的典型用法代碼示例。如果您正苦於以下問題:PHP Curl::success方法的具體用法?PHP Curl::success怎麽用?PHP Curl::success使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Curl
的用法示例。
在下文中一共展示了Curl::success方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: get
public function get($url_mixed, $data = array())
{
if (is_array($url_mixed)) {
$curl_multi = curl_multi_init();
$this->multi_parent = true;
$this->curls = array();
foreach ($url_mixed as $url) {
$curl = new Curl();
$curl->multi_child = true;
$curl->beforeSend($this->before_send_function);
$curl->success($this->success_function);
$curl->error($this->error_function);
$curl->complete($this->complete_function);
$curl->base_url = $url;
$curl->url = $this->buildURL($url, $data);
$curl->setOpt(CURLOPT_URL, $curl->url, $curl->curl);
$curl->setOpt(CURLOPT_CUSTOMREQUEST, 'GET');
$curl->setOpt(CURLOPT_HTTPGET, true);
$this->curls[] = $curl;
$curlm_error_code = curl_multi_add_handle($curl_multi, $curl->curl);
if (!($curlm_error_code === CURLM_OK)) {
throw new \ErrorException('cURL multi add handle error: ' . curl_multi_strerror($curlm_error_code));
}
}
foreach ($this->curls as $ch) {
foreach ($this->options as $key => $value) {
$ch->setOpt($key, $value);
}
}
do {
curl_multi_select($curl_multi);
$status = curl_multi_exec($curl_multi, $active);
} while ($status === CURLM_CALL_MULTI_PERFORM || $active);
while (!($info_array = curl_multi_info_read($curl_multi)) === false) {
if (!($info_array['msg'] === CURLMSG_DONE)) {
continue;
}
foreach ($this->curls as $ch) {
if ($ch->curl === $info_array['handle']) {
$ch->curl_error_code = $info_array['result'];
break;
}
}
}
foreach ($this->curls as $ch) {
$this->exec($ch);
}
} else {
$this->base_url = $url_mixed;
$this->url = $this->buildURL($url_mixed, $data);
$this->setOpt(CURLOPT_URL, $this->url);
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'GET');
$this->setOpt(CURLOPT_HTTPGET, true);
return $this->exec();
}
}
示例2: testErrorCallback
public function testErrorCallback()
{
$success_called = FALSE;
$error_called = FALSE;
$complete_called = FALSE;
$curl = new Curl();
$curl->setHeader('X-DEBUG-TEST', 'get');
$curl->setOpt(CURLOPT_SSL_VERIFYPEER, FALSE);
$curl->setOpt(CURLOPT_SSL_VERIFYHOST, FALSE);
$curl->setOpt(CURLOPT_CONNECTTIMEOUT_MS, 2000);
$curl->success(function ($instance) use(&$success_called, &$error_called, &$complete_called) {
PHPUnit_Framework_Assert::assertInstanceOf('Curl', $instance);
PHPUnit_Framework_Assert::assertFalse($success_called);
PHPUnit_Framework_Assert::assertFalse($error_called);
PHPUnit_Framework_Assert::assertFalse($complete_called);
$success_called = TRUE;
});
$curl->error(function ($instance) use(&$success_called, &$error_called, &$complete_called, &$curl) {
PHPUnit_Framework_Assert::assertInstanceOf('Curl', $instance);
PHPUnit_Framework_Assert::assertFalse($success_called);
PHPUnit_Framework_Assert::assertFalse($error_called);
PHPUnit_Framework_Assert::assertFalse($complete_called);
$error_called = TRUE;
});
$curl->complete(function ($instance) use(&$success_called, &$error_called, &$complete_called) {
PHPUnit_Framework_Assert::assertInstanceOf('Curl', $instance);
PHPUnit_Framework_Assert::assertFalse($success_called);
PHPUnit_Framework_Assert::assertTrue($error_called);
PHPUnit_Framework_Assert::assertFalse($complete_called);
$complete_called = TRUE;
});
$curl->get(Test::ERROR_URL);
$this->assertFalse($success_called);
$this->assertTrue($error_called);
$this->assertTrue($complete_called);
}