本文整理汇总了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);
}