0

问题

在生产服务器上,我的代码(见下文)产生了意想不到的401 error. 但是,它在我的开发服务器上运行良好。我一直在尝试修复由意外引起的性能401 error。由于我的代码在开发服务器上运行良好,我不相信PHP代码会导致错误。

任何建议或指导将不胜感激!


代码

$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);

这些是curl_info生产和开发服务器的响应。

生产(性能缓慢)

卷曲信息

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 
) 

第一反应 (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

第二响应(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字符串:

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

发展(良好的表现)

卷曲信息

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
) 

第一反应 (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 

第二反应 (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字符串:

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

1 回答 1

0
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));

是罪魁祸首。几天后,它现在已修复。

于 2015-05-05T04:18:24.160 回答