काम करती है जब मैं कुछ यूआरएल के लिए PHP के कर्ल विधियों का उपयोग करने का प्रयास करता हूं, तो यह समय समाप्त हो जाता है। जब मैं एक ही यूआरएल के लिए कमांडलाइन का उपयोग करता हूं, तो यह ठीक काम करता है।PHP कर्ल विधियों का समय, लेकिन कमांड लाइन हमेशा
मैं एडब्ल्यूएस का उपयोग कर रहा हूं और एक t2.medium बॉक्स yum से php-55 अपाचे लाइब्रेरी चला रहा है।
function curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36');
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 2);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept-Language: en-us'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
$fh = fopen('/home/ec2-user/curllog', 'w');
curl_setopt($ch, CURLOPT_STDERR, $fh);
$a = curl_exec($ch);
curl_close($ch);
fclose($fh);
$headers = explode("\n",$a);
var_dump($headers);
var_dump($a);
exit;
return $result;
}
तो यहाँ कॉल कि ठीक काम करता है::
यहाँ मेरी PHP कोड है
curl('http://www.google.com');
और यह गूगल के मुखपृष्ठ के लिए डेटा देता है।
हालांकि, मैं एक और यूआरएल की कोशिश:
curl('http://www.trulia.com/profile/agent-1391347/overview');
और मैं curllog में यह मिलता है:
curl -s www.trulia.com/profile/agent-1391347/overview
यह:
[[email protected] Node]$ cat ../curllog
* Hostname was NOT found in DNS cache
* Trying 23.0.160.99...
* Connected to www.trulia.com (23.0.160.99) port 80 (#0)
> GET /profile/agent-1391347/overview HTTP/1.1
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36
Host: www.trulia.com
Accept: */*
Accept-Language: en-us
* Operation timed out after 10002 milliseconds with 0 bytes received
* Closing connection 0
अगर मैं कमांड लाइन से इस चलाने तत्काल रिटर्न (1 सेकंड के भीतर) कोई आउटपुट के साथ। यह उम्मीद है। हालांकि जब मैं इसे चलाता हूं:
curl -sL www.trulia.com/profile/agent-1391347/overview
यह पृष्ठ ठीक तरह से देता है, जैसा कि मैं चाहता हूं।
तो, मेरे कर्ल के साथ क्या गलत है?
curl
cURL support => enabled
cURL Information => 7.38.0
Age => 3
Features
AsynchDNS => Yes
CharConv => No
Debug => No
GSS-Negotiate => No
IDN => Yes
IPv6 => Yes
krb4 => No
Largefile => Yes
libz => Yes
NTLM => Yes
NTLMWB => Yes
SPNEGO => Yes
SSL => Yes
SSPI => No
TLS-SRP => No
Protocols => dict, file, ftp, ftps, gopher, http, https, imap, imaps, ldap, ldaps, pop3, pop3s, rtsp, scp, sftp, smtp, smtps, telnet, tftp
Host => x86_64-redhat-linux-gnu
SSL Version => NSS/3.16.2 Basic ECC
ZLib Version => 1.2.7
libSSH Version => libssh2/1.4.2
क्या आप उसी मशीन से कमांड लाइन को PHP कोड के रूप में चला रहे हैं? यदि नहीं, तो आप कर्ल संस्करण की तुलना करना चाह सकते हैं। –
टर्मिनल 'curl --version' का आउटपुट क्या है? और ' php var_dump (curl_version()) का आउटपुट क्या है;'? – hanshenrik
आईआरसी स्निपेट: https://i.imgur.com/bOwxcS3.png - ... और जिस व्यक्ति ने उत्तर दिया, वह लेखक है (lib-) curl – hanshenrik