本文整理匯總了PHP中Curl\Curl::complete方法的典型用法代碼示例。如果您正苦於以下問題:PHP Curl::complete方法的具體用法?PHP Curl::complete怎麽用?PHP Curl::complete使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Curl\Curl
的用法示例。
在下文中一共展示了Curl::complete方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: pushWithTemplate
protected function pushWithTemplate(SendCloudMessage $message, $template, array $data)
{
// 構造參數
// 如果 不使用 maillist
if (empty($message->maillist())) {
if (empty($data)) {
// 不需要模板數據, 構造無用填充數據
$data = ['nothing' => $message->to()];
}
$param = $this->buildParamWithMessage($message, ['use_maillist' => 'false', 'substitution_vars' => json_encode(['to' => $message->to(), 'sub' => $data]), 'template_invoke_name' => $template]);
} else {
$param = $this->buildParamWithMessage($message, ['use_maillist' => 'true', 'to' => implode(';', $message->maillist()), 'template_invoke_name' => $template]);
}
$curl = new Curl();
// 發送回調
$curl->complete(function (Curl $instance) {
$this->checkError($instance);
});
// 發送
$curl->post(self::API_MAIL_SEND_TEMPLATE, $param);
return $this;
}
示例2: Curl
<?php
require '../src/Curl/Curl.php';
use Curl\Curl;
$curl = new Curl();
$curl->progress(function ($client, $download_size, $downloaded, $upload_size, $uploaded) {
if ($download_size === 0) {
return;
}
// Display a progress bar: xxx% [=======> ]
$progress_size = 40;
$fraction_downloaded = $downloaded / $download_size;
$dots = round($fraction_downloaded * $progress_size);
printf('%3.0f%% [', $fraction_downloaded * 100);
$i = 0;
for (; $i < $dots - 1; $i++) {
echo '=';
}
echo '>';
for (; $i < $progress_size - 1; $i++) {
echo ' ';
}
echo ']' . "\r";
});
$curl->complete(function ($instance) {
echo "\n" . 'download complete' . "\n";
});
$curl->download('https://php.net/distributions/manual/php_manual_en.html.gz', '/tmp/php_manual_en.html.gz');
示例3: request
/**
* Make a request
* @param string $route the route to call
* @return Curl
* @throws ApiException
*/
protected static function request($route = '')
{
$accessToken = self::getAccessToken();
$curl = new Curl();
$curl->base_url = $accessToken->url . ($route != '' ? $route : '');
$curl->setHeader('Authorization', $accessToken->token);
$curl->complete(function () use($curl) {
$curl->close();
});
$curl->error(function () use($curl) {
$message = is_object($curl->response) ? $curl->response->message : $curl->error_message;
throw new ApiException($message);
});
return $curl;
}