本文整理汇总了PHP中curl_strerror函数的典型用法代码示例。如果您正苦于以下问题:PHP curl_strerror函数的具体用法?PHP curl_strerror怎么用?PHP curl_strerror使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了curl_strerror函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: file_get_html_with_retry
function file_get_html_with_retry($url, $retrytimes = 5, $timeoutsec = 1)
{
global $errormsg;
$errno = 0;
for ($loopcount = 0; $loopcount < $retrytimes; $loopcount++) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36");
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeoutsec);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeoutsec);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
$contents = curl_exec($ch);
//var_dump($contents); //debug
if ($contents !== false) {
curl_close($ch);
break;
}
$errno = curl_errno($ch);
$errormsg = curl_error($ch);
print $timeoutsec;
curl_close($ch);
}
if ($loopcount === $retrytimes) {
$error_message = curl_strerror($errno);
print 'http connection error : ' . $error_message . ' url : ' . $url . "\n";
}
return $contents;
}
示例2: call
/**
* @param Request $request
* @return Response
*/
public function call(Request $request)
{
// Create cURL
$ch = curl_init();
// Set-up URL
curl_setopt($ch, CURLOPT_URL, $request->getUrl());
// Set-up headers
$headers = $request->getHeaders();
array_walk($headers, function (&$item, $key) {
$item = "{$key}: {$item}";
});
curl_setopt($ch, CURLOPT_HTTPHEADER, array_values($headers));
// Set-up others
curl_setopt_array($ch, $request->getOpts());
// Receive result
$result = curl_exec($ch);
// Parse response
$response = new Response();
if ($result === FALSE) {
$response->setError(curl_strerror(curl_errno($ch)));
$response->setData(FALSE);
$response->setCode(curl_errno($ch));
$response->setHeaders(curl_getinfo($ch));
} else {
$response->setData(json_decode($result));
$response->setCode(curl_getinfo($ch, CURLINFO_HTTP_CODE));
$response->setHeaders(curl_getinfo($ch));
}
// Close cURL
curl_close($ch);
return $response;
}
示例3: push
/**
* @param $uri
* @param $target type of notification
* @param $delay immediate, in 450sec or in 900sec
* @param $messageId The optional custom header X-MessageID uniquely identifies a notification message. If it is present, the same value is returned in the notification response. It must be a string that contains a UUID
* @param $message The message to send
*
* @throws PushException
* @return array
*/
private function push($uri, $target, $delay, $messageId, $message)
{
$headers = array('Content-Type: text/xml', 'Accept: application/*', "X-NotificationClass: {$delay}");
if ($messageId != NULL) {
$headers[] = "X-MessageID: {$messageId}";
}
if ($target != NULL) {
$headers[] = "X-WindowsPhone-Target:{$target}";
}
$request = curl_init();
curl_setopt($request, CURLOPT_HEADER, true);
curl_setopt($request, CURLOPT_HTTPHEADER, $headers);
curl_setopt($request, CURLOPT_POST, true);
curl_setopt($request, CURLOPT_POSTFIELDS, $message);
curl_setopt($request, CURLOPT_URL, $uri);
curl_setopt($request, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($request);
if ($errorNumber = curl_errno($request)) {
$errorMessage = curl_strerror($errorNumber);
throw new PushException($errorMessage, $errorNumber);
}
curl_close($request);
$result = array();
foreach (explode("\n", $response) as $line) {
$tab = explode(":", $line, 2);
if (count($tab) == 2) {
$result[$tab[0]] = trim($tab[1]);
}
}
return $result;
}
示例4: crudAction
public function crudAction($action = 'create')
{
switch ($action) {
case 'create':
curl_setopt($this->curlHandler, CURLOPT_CUSTOMREQUEST, "POST");
break;
case 'update':
curl_setopt($this->curlHandler, CURLOPT_CUSTOMREQUEST, "PUT");
break;
case 'read':
curl_setopt($this->curlHandler, CURLOPT_CUSTOMREQUEST, "GET");
break;
case 'delete':
curl_setopt($this->curlHandler, CURLOPT_CUSTOMREQUEST, "DELETE");
break;
}
if (!empty($this->jsonData)) {
curl_setopt($this->curlHandler, CURLOPT_POSTFIELDS, $this->jsonData);
}
curl_setopt($this->curlHandler, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->curlHandler, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($this->jsonData)));
$this->apiReponse = curl_exec($this->curlHandler);
if ($errno = curl_errno($this->curlHandler)) {
$error_message = curl_strerror($errno);
echo "cURL error ({$errno}):\n {$error_message}";
}
curl_close($this->curlHandler);
}
示例5: post
public static function post($url, $postFields = null, $headers = null)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, is_array($postFields) ? self::getPostHttpBody($postFields) : $postFields);
if (self::$readTimeout) {
curl_setopt($ch, CURLOPT_TIMEOUT, self::$readTimeout);
}
if (self::$connectTimeout) {
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, self::$connectTimeout);
}
// https request
if (strlen($url) > 5 && strtolower(substr($url, 0, 5)) == "https") {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}
if (is_array($headers) && 0 < count($headers)) {
$httpHeaders = self::getHttpHearders($headers);
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeaders);
}
$httpResponse = new HttpResponse();
$httpResponse->setBody(curl_exec($ch));
$httpResponse->setStatus(curl_getinfo($ch, CURLINFO_HTTP_CODE));
if ($errno = curl_errno($ch)) {
throw new Exception(curl_strerror($errno));
}
curl_close($ch);
return $httpResponse->getBody();
}
示例6: connect
public function connect()
{
$this->open();
$sendData = $this->serializeParams($this->getParameters());
curl_setopt($this->curl, CURLOPT_URL, "{$this->url}?{$sendData}");
//curl_setopt($this->curl, CURLOPT_POST, true); // HTTP POST
//curl_setopt($this->curl, CURLOPT_POSTFIELDS, $sendData);
$response = curl_exec($this->curl);
if ($response === false) {
$errno = @curl_errno($this->curl);
$error = @curl_strerror($errno);
$this->close();
throw TransferException::couldNotTransferData($this->url . ($this->isProxy() ? ' (usando proxy)' : ''), "[{$errno}] {$error}");
}
list($response_headers_str, $response) = explode("\r\n\r\n", $response);
/*$response_headers = $this->_readHeaders($response_headers_str);
if (!$this->checkResponseToken($response_headers['X-FW-Response'])) {
throw new WrongDataTransferException('Resposta inv�lida do servidor, entre em contato com a Furac�o');
}*/
$this->close();
if (empty($response)) {
throw TransferException::emptyDataReturned();
}
return $response;
}
示例7: getErrorMessage
public function getErrorMessage()
{
if ($this->errNo) {
return curl_strerror($this->errNo);
}
return null;
}
示例8: __construct
/**
* @param string|null $message
*/
public function __construct(RequestInterface $request, Response $response, $message = null)
{
$this->request = $request;
$this->response = $response;
if ($message === null) {
$curlError = $response->getHeader('X-Curl-Error-Result');
$message = sprintf('HTTP %s request to "%s%s" failed: %d - "%s".', $request->getMethod(), $request->getHost(), $request->getResource(), $curlError ?: $response->getStatusCode(), $curlError ? curl_strerror($curlError) : $response->getReasonPhrase());
}
parent::__construct($message);
}
示例9: createResultCollection
/**
* createResultCollection.
*
* @param bool $hasError
*/
public function createResultCollection($hasError = false)
{
$errorLog = null;
if ($hasError) {
$errorLog = curl_strerror(5);
}
$result = new Result($this->createUrlInfo(), $hasError ? 400 : 200, 0.42, $errorLog);
$resultCollection = new ResultCollection();
$resultCollection->append($result);
return $resultCollection;
}
示例10: execute
private function execute($curl)
{
$body = curl_exec($curl);
if ($errno = curl_errno($curl)) {
$error_message = curl_strerror($errno);
throw new HttpException("cURL error ({$errno}): {$error_message}", 0, $this->url);
}
$statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$contentType = curl_getinfo($curl, CURLINFO_CONTENT_TYPE);
curl_close($curl);
return array($statusCode, $contentType, $body);
}
示例11: processCommand
/**
* Performs Aspose Api Request.
*
* @param string $url Target Aspose API URL.
* @param string $method Method to access the API such as GET, POST, PUT and DELETE
* @param string $headerType XML or JSON
* @param string $src Post data.
* @param string $returnType
* @return string
* @throws Exception
*/
public static function processCommand($url, $method = 'GET', $headerType = 'XML', $src = '', $returnType = 'xml')
{
$dispatcher = AsposeApp::getEventDispatcher();
$method = strtoupper($method);
$headerType = strtoupper($headerType);
AsposeApp::getLogger()->info("Aspose Cloud SDK: processCommand called", array('url' => $url, 'method' => $method, 'headerType' => $headerType, 'src' => $src, 'returnType' => $returnType));
$session = curl_init();
curl_setopt($session, CURLOPT_URL, $url);
if ($method == 'GET') {
curl_setopt($session, CURLOPT_HTTPGET, 1);
} else {
curl_setopt($session, CURLOPT_POST, 1);
curl_setopt($session, CURLOPT_POSTFIELDS, $src);
curl_setopt($session, CURLOPT_CUSTOMREQUEST, $method);
}
curl_setopt($session, CURLOPT_HEADER, false);
if ($headerType == 'XML') {
curl_setopt($session, CURLOPT_HTTPHEADER, array('Accept: application/' . $returnType . '', 'Content-Type: application/xml', 'x-aspose-client: PHPSDK/v1.0'));
} else {
curl_setopt($session, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'x-aspose-client: PHPSDK/v1.0'));
}
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
if (preg_match('/^(https)/i', $url)) {
curl_setopt($session, CURLOPT_SSL_VERIFYPEER, false);
}
// Allow users to register curl options before the call is executed
$event = new ProcessCommandEvent($session);
$dispatcher->dispatch(ProcessCommandEvent::PRE_CURL, $event);
$result = curl_exec($session);
$headers = curl_getinfo($session);
if (substr($headers['http_code'], 0, 1) != '2') {
if (curl_errno($session) !== 0) {
throw new AsposeCurlException(curl_strerror(curl_errno($session)), $headers, curl_errno($session));
AsposeApp::getLogger()->warning(curl_strerror(curl_errno($session)));
} else {
throw new Exception($result);
AsposeApp::getLogger()->warning($result);
}
} else {
if (preg_match('/You have processed/i', $result) || preg_match('/Your pricing plan allows only/i', $result)) {
AsposeApp::getLogger()->alert($result);
throw new Exception($result);
}
}
// Allow users to alter the result
$event = new ProcessCommandEvent($session, $result);
/** @var ProcessCommandEvent $dispatchedEvent */
$dispatchedEvent = $dispatcher->dispatch(ProcessCommandEvent::POST_CURL, $event);
curl_close($session);
// TODO test or the Event result needs to be returned in case an listener was triggered
return $dispatchedEvent->getResult();
}
示例12: sendRequest
/**
* Curl request to giving url
*
* @param string $url
* @param array $param
*
* @return array
*/
public function sendRequest($url, $param)
{
$curl = curl_init($url);
curl_setopt_array($curl, array(CURLOPT_VERBOSE => 1, CURLOPT_SSL_VERIFYPEER => 0, CURLOPT_SSL_VERIFYHOST => 0, CURLOPT_RETURNTRANSFER => 1, CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $param));
$getResult = curl_exec($curl);
if ($errno = curl_errno($curl)) {
$message = curl_strerror($errno);
throw new CurlErrorException("CURL error : {$message}");
}
curl_close($curl);
parse_str($getResult, $result);
return $result;
}
示例13: doRequest
/**
* Process API requests to github and packagist
*
* @param $url
* @param array $headers
* @return mixed
*/
private static function doRequest($url, $headers = [])
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$response = curl_exec($ch);
if (0 !== ($errno = curl_errno($ch))) {
$errorMessage = curl_strerror($errno);
Yii::$app->session->setFlash("cURL error ({$errno}):\n {$errorMessage}");
}
curl_close($ch);
return $response;
}
示例14: __construct
/**
* @param array $messages - array of [$request, $response]
* @param string|null $errorMessage
*/
public function __construct(array $messages, $errorMessage = null)
{
$this->messages = $messages;
$errorMessages = [];
if ($errorMessage === null) {
foreach ($this->messages as $messages) {
/** @var RequestInterface $request */
/** @var Response $response */
list($request, $response) = $messages;
$curlError = $response->getHeader('X-Curl-Error-Result');
$errorMessages[] = sprintf('%s "%s%s": %d - "%s"', $request->getMethod(), $request->getHost(), $request->getResource(), $curlError ?: $response->getStatusCode(), $curlError ? curl_strerror($curlError) : $response->getReasonPhrase());
}
$errorMessage = sprintf("Batch HTTP requests failed.\n - %s.", implode("\n - ", $errorMessages));
}
list($request, $response) = current($this->messages);
parent::__construct($request, $response, $errorMessage);
}
示例15: testCurlErrors
public function testCurlErrors()
{
$expectedErrorCodeByDomain = array('' => CURLE_URL_MALFORMAT, 'foo://bar' => CURLE_UNSUPPORTED_PROTOCOL, 'http://non-existing-domain' => CURLE_COULDNT_RESOLVE_HOST, 'https://expired.badssl.com' => CURLE_SSL_CACERT);
foreach ($expectedErrorCodeByDomain as $domain => $expectedErrorCode) {
try {
$this->connection->get($domain, []);
} catch (ErrorException $e) {
$expectedErrorMessage = 'cURL error ' . $expectedErrorCode;
if (function_exists('curl_strerror')) {
$expectedErrorMessage .= ' (' . curl_strerror($expectedErrorCode) . ')';
}
$this->assertEquals($expectedErrorMessage, $e->getMessage());
continue;
}
$this->fail('An expected exception has not been raised');
}
}