2016-11-25 1 views
0

タイトルが不適切な場合はお詫び申し上げますが、私はそれについてより良い定義を考えることができませんでした。cURL GETメソッドがPHPで失敗しますが、ブラウザとコンソールで正常に完了します

私はこの問題を解決するつもりです。私は過去5年以上にわたりcURLを介してフィードとデータを収集してきましたが、この種の状況に遭遇したことはありません。私はこの https://private.example.com/thisDotNetEndPoint?token=bla-bla-trutj&someParam=1

someParamが変更可能であり、データのすべての少ない量でいくつかの値については、正常に動作し、ほぼ同じ速度のようになりますアドレスからHTTPS経由でリモートサーバからのGETメソッドを介して収集するための大規模なJSONを持っていますブラウザに、しかし、いくつかのケースではカール常にブラウザで、コンソールのすべてのものからは正常に動作している間、設定tiomeoutに行く

PHP

次のように私のカールがある:

$ch = curl_init(); 
$url = 'https://private.example.com/thisDotNetEndPoint?token=bla-bla-trutj&someParam=1'; 
curl_setopt($ch, CURLOPT_URL, $url); 

curl_setopt($ch, CURLOPT_HEADER, 0); 
// I've added this user agent as it is the same as the one Chrome uses 
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36'); 

curl_setopt($ch, CURLOPT_POST, 0); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); 
// I have tried removing the SSL part below, but no difference 
curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, "HIGH:!SSLv3s"); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // tried this with true, but no difference 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); 
curl_setopt($ch, CURLOPT_TIMEOUT, 1200); // what ever the timeout I set the cURL always goes to timeout 
curl_setopt($ch, CURLOPT_VERBOSE, true); 

$response = curl_exec($ch); 
if (curl_errno($ch)) { 
    print("cURL error: " . curl_error($ch)); 
    print_r(curl_getinfo($ch)); 
} else { 
    print_r(json_decode($response)); 
} 
curl_close($ch); 

これは冗長な出力です:

* Hostname was NOT found in DNS cache 
* Trying 12.34.567.89... 
* Connected to private.example.com (12.34.567.89) port 443 (#0) 
* successfully set certificate verify locations: 
* CAfile: none 
    CApath: /etc/ssl/certs 
* SSL connection using ECDHE-RSA-AES256-SHA384 
* Server certificate: 
* subject: OU=Domain Control Validated; CN=*.example.com 
* start date: 2016-03-03 09:41:38 GMT 
* expire date: 2018-03-04 09:52:18 GMT 
* subjectAltName: private.example.com matched 
* issuer: C=US; ST=Arizona; L=Scottsdale; O=Starfield Technologies, Inc.; OU=http://certs.starfieldtech.com/repository/; CN=Starfield Secure Certificate Authority - G2 
* SSL certificate verify ok. 
> GET /thisDotNetEndPoint?token=bla-bla-trutj&someParam=1 HTTP/1.1 
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36 
Host: private.example.com 
Accept: */*                    */ 
* Operation timed out after 1200001 milliseconds with 0 bytes received 
* Closing connection 0 

それはいつも私が設定TIMOUTが、でも2時間に設定する試みたものは何でもTIMOUTに進みます。

私も、これらが、違いはありません追加しようとしました:私は、ブラウザで同じURLを入力すると、応答が6-9分

に戻ってくる

curl_setopt($ch, CURLOPT_NOSIGNAL, 1); 

curl_setopt($ch, CURLOPT_LOW_SPEED_LIMIT, 1); 
curl_setopt($ch, CURLOPT_LOW_SPEED_TIME, 1200); 

ブラウザをcURLコンソール

私は最も単純なc ommandと、それはブラウザと同じ時間で動作します。

$ curl -X GET -v 'https://private.example.com/thisDotNetEndPoint?token=bla-bla-trutj&someParam=1' 

冗長な出力:

* Hostname was NOT found in DNS cache 
* Trying 12.34.567.89... 
* Connected to private.example.com (12.34.567.89) port 443 (#0) 
* successfully set certificate verify locations: 
* CAfile: none 
    CApath: /etc/ssl/certs 
* SSLv3, TLS handshake, Client hello (1): 
* SSLv3, TLS handshake, Server hello (2): 
* SSLv3, TLS handshake, CERT (11): 
* SSLv3, TLS handshake, Server key exchange (12): 
* SSLv3, TLS handshake, Server finished (14): 
* SSLv3, TLS handshake, Client key exchange (16): 
* SSLv3, TLS change cipher, Client hello (1): 
* SSLv3, TLS handshake, Finished (20): 
* SSLv3, TLS change cipher, Client hello (1): 
* SSLv3, TLS handshake, Finished (20): 
* SSL connection using ECDHE-RSA-AES256-SHA384 
* Server certificate: 
* subject: OU=Domain Control Validated; CN=*.example.com 
* start date: 2016-03-03 09:41:38 GMT 
* expire date: 2018-03-04 09:52:18 GMT 
* subjectAltName: private.example.com matched 
* issuer: C=US; ST=Arizona; L=Scottsdale; O=Starfield Technologies, Inc.; OU=http://certs.starfieldtech.com/repository/; CN=Starfield Secure Certificate Authority - G2 
* SSL certificate verify ok. 
> GET /thisDotNetEndPoint?token=bla-bla-trutj&someParam=1 HTTP/1.1 
> User-Agent: curl/7.35.0 
> Host: private.example.com 
> Accept: */*                    */ 
> 
< HTTP/1.1 200 OK 
< Cache-Control: private 
< Content-Type: application/json; charset=utf-8 
< Server: Microsoft-IIS/8.5 
< X-StackifyID: V1|b8b10c35-2649-4f67-ba6a-b5ad15ef553b|C56050|CD18| 
< Set-Cookie: .ASPXANONYMOUS=looI88UVBp6Cg5tLkzVejO4CNRilhyKjMY4hFqhuO48vdVT19U8h5oisC9khFv1rOmH6Ii_lEec-9XhipEvh1UkewhufqfmlTGFsyQCaML06NVa-5-Vr_OikZb07R6pdHCeRtn9liBVJfamJmXiElA2; expires=Thu, 02-Feb-2017 20:54:18 GMT; path=/; HttpOnly 
< X-AspNetMvc-Version: 5.2 
< Rx-CID: ae9907d6fc394b24b6599e74ab5a668f 
< Rx_RequestId: f3fff82c4de04bba90b2bbc5704ac787 
< X-Powered-By: ASP.NET 
< Strict-Transport-Security: max-age=31536000 
< Access-Control-Allow-Origin: * 
< Access-Control-Allow-Headers: rx-cid 
< Date: Fri, 25 Nov 2016 10:25:00 GMT 
< Content-Length: 2231472 
< 
[and the response is printed here] 

任意のアイデア?

ありがとうございます。

答えて

0

あなたはコンソールとあなたのPHPの冗長出力の違いに気付きましたか?あなたのPHPコードにuseragentがありません。 curlコマンドラインはデフォルトでこのユーザエージェントを追加しますが、php-curlは追加しません。

User-Agent: curl/7.35.0 

オプションCURLOPT_USERAGENTを使用してください。

curl_setopt($ch, CURLOPT_USERAGENT, "Opera 11.0"); 
+0

実際にはそれとは関係ありません。とにかく私はすでにユーザーエージェントを追加しようとしましたが、結果は同じです(質問を編集しました)。 –

関連する問題