简体   繁体   English

Live Server上与处理PHP Curl API有关的意外401错误

[英]Unexpected 401 Error on Live Server related to processing PHP Curl API

Problem 问题

On production server, my code (See below) produces an unexpected 401 error . 在生产服务器上,我的代码(请参见下文)产生意外的401 error However, it works fine on my development server. 但是,它在我的开发服务器上工作正常。 I have been trying to fix performance caused by the unexpected 401 error . 我一直在尝试解决由意外401 error引起的性能。 Since my code works fine on Development server, I don't believe the PHP code is causing the error. 由于我的代码在开发服务器上工作正常,因此我不认为PHP代码会导致该错误。

Any advise or guidance would be greatly appreciated! 任何建议或指导将不胜感激!


Code

$ch = curl_init();
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); 
curl_setopt($ch, CURLOPT_USERPWD, $VAR:$VAR2);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "|MY API V1.0|");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json','Content-Length: ' . strlen($POST)));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $POST);

These are the curl_info responses for both, production and development, servers. 这些是针对生产和开发服务器的curl_info响应。

Production (Slow Performance) 生产(性能低下)

CURL Info CURL信息

Array ( 
  [url] => https://example.com/v0.1.0/token/create-token.hcw
  [content_type] => text/html; charset=utf-8 
  [http_code] => 200
  [header_size] => 685 
  [request_size] => 766 
  [filetime] => -1
  [ssl_verify_result] => 18 
  [redirect_count] => 1 
  [total_time] => 20.13144 
  [namelookup_time] => 0.000381 
  [connect_time] => 0.000473 
  [pretransfer_time] => 0.010784 
  [size_upload] => 0 
  [size_download] => 80 
  [speed_download] => 3 
  [speed_upload] => 0 
  [download_content_length] => 80 
  [upload_content_length] => 0 
  [starttransfer_time] => 0.067625 
  [redirect_time] => 20.063809 
) 

First Response (401) 第一回应(401)

HTTP/1.0 401 Unauthorized 
Date: Mon, 04 May 2015 02:19:46 GMT 
Server: Apache 
WWW-Authenticate: Digest realm="MY API",qop="auth",nonce="5546d75645e7d",opaque="5c4c3e3231714690a63d174
a9cf26780" 
Cache-Control: max-age=0 
Expires: Mon, 04 May 2015 02:19:46
GMT X-Powered-By: PleskLin 
X-UA-Compatible: IE=Edge,chrome=1
Content-Length: 111 
Connection: close 
Content-Type: text/html; charset=utf-8

Second Response (200 - After 20+ Seconds Delay) 秒响应(200-延迟20秒后)

HTTP/1.1 200 OK 
Date: Mon, 04 May 2015 02:20:06 GMT
Server: Apache 
Cache-Control: max-age=0 
Expires: Mon, 04 May 2015 02:20:06 GMT 
X-Powered-By: PleskLin 
X-UA-Compatible: IE=Edge,chrome=1
Content-Length: 80 
Connection: close 
Content-Type: text/html; charset=utf-8

JSON String: JSON字符串:

{"response":"success", "content":[{"token":"ko67atw1CFRSEdllOyeklRIMPb1ZS0a0"}]}

Development (Good Performance) 发展(良好绩效)

CURL Info CURL信息

Array ( 
  [url] => http://localhost/mydomain/v0.1.0/token/create-token.hcw
  [content_type] => text/html; charset=utf-8 
  [http_code] => 200 
  [header_size] => 736 
  [request_size] => 348 
  [filetime] => -1 
  [ssl_verify_result] => 0
  [redirect_count] => 1 
  [total_time] => 0.005946 
  [namelookup_time] => 8.0E-5 
  [connect_time] => 8.3E-5 
  [pretransfer_time] => 0.000133 
  [size_upload] => 20 
  [size_download] => 0 
  [speed_download] => 0
  [speed_upload] => 3363 
  [download_content_length] => 0
  [upload_content_length] => 20 
  [starttransfer_time] => 0.002765
  [redirect_time] => 0.003146
) 

First Response (200) 急救(200)

HTTP/1.1 200 OK 
Date: Mon, 04 May 2015 02:33:40 GMT 
Server: Apache/2.2.14 (Unix) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l PHP/5.3.1 mod_perl/2.0.4 Perl/v5.10.1 
X-Powered-By: PHP/5.3.1 
Cache-Control: max-age=0 
Expires: Mon, 04 May 2015 02:33:40 GMT 
X-UA-Compatible: IE=Edge,chrome=1 
Vary: Accept-Encoding
Content-Length: 0 
Content-Type: text/html; charset=utf-8 

Second Response (200) 第二反应(200)

HTTP/1.1 200 OK 
Date: Mon, 04 May 2015 02:33:40 GMT 
Server: Apache/2.2.14 (Unix) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l PHP/5.3.1 mod_perl/2.0.4 Perl/v5.10.1 
X-Powered-By: PHP/5.3.1 
Cache-Control: max-age=0 
Expires: Mon, 04 May 2015 02:33:40 GMT 
X-UA-Compatible: IE=Edge,chrome=1 
Vary: Accept-Encoding 
Content-Length: 0 
Content-Type: text/html; charset=utf-8

JSON String: JSON字符串:

{"response":"success", "content":[{"token":"ko67atw1CFRSEdllOyeklRIMPb1ZS0a0"}]}
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));

was the culprit. 是罪魁祸首。 After many days it is now fixed. 许多天后,现在已修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM