8

This is the code I am using:

curl -k https://www.ashleydirect.com/graphics/ad_images/T908-6.jpg

This works fine (the "-k" flag is necessary for it to work or it times out)

I then use this code in PHP:

$ch = curl_init("https://www.ashleydirect.com/graphics/ad_images/T908-6.jpg");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);

And it times out -- I've tried a ton of variations, but $result is always false.

This is the PHP cURL information when I do phpinfo():

cURL support enabled
cURL Information 7.38.0
Age 3
Features
AsynchDNS No
Debug No
GSS-Negotiate No
IDN Yes
IPv6 Yes
Largefile Yes
NTLM Yes
SPNEGO No
SSL Yes
SSPI No
krb4 No
libz Yes
CharConv No
Protocols dict, file, ftp, ftps, gopher, http, https, imap, imaps, pop3, pop3s, rtsp, smtp, smtps, telnet, tftp
Host x86_64-unknown-linux-gnu
SSL Version OpenSSL/1.0.1e
ZLib Version 1.2.3

Any ideas would be greatly appreciated.


UPDATE

Here is the information from curl_getinfo($ch):

array (
  'url' => 'https://www.ashleydirect.com/graphics/ad_images/T908-6.jpg',
  'content_type' => NULL,
  'http_code' => 0,
  'header_size' => 0,
  'request_size' => 0,
  'filetime' => -1,
  'ssl_verify_result' => 1,
  'redirect_count' => 0,
  'total_time' => 59.27538100000000298450686386786401271820068359375,
  'namelookup_time' => 0.00975999999999999957867036215475309290923178195953369140625,
  'connect_time' => 0.05170500000000000095923269327613525092601776123046875,
  'pretransfer_time' => 0,
  'size_upload' => 0,
  'size_download' => 0,
  'speed_download' => 0,
  'speed_upload' => 0,
  'download_content_length' => -1,
  'upload_content_length' => -1,
  'starttransfer_time' => 0,
  'redirect_time' => 0,
  'certinfo' => 
  array (
  ),
  'primary_ip' => '65.207.240.29',
  'primary_port' => 443,
  'local_ip' => '172.24.32.132',
  'local_port' => 54461,
  'redirect_url' => '',
)

UPDATE 2

Response from curl_error:

Unknown SSL protocol error in connection to www.ashleydirect.com:443

UPDATE 3 - Solution

I wanted to clearly put the solution I came up with, thanks to @Valery Viktorovsky who pointed out they only accept TLS 1.0.

The solution, then was to add this:

// Set to TLS 1.0 (CURL_SSLVERSION_TLSv1_0)
curl_setopt($ch, CURLOPT_SSLVERSION, 4);

More information here

5
  • 1
    Are you behind a proxy? Commented Aug 19, 2015 at 21:29
  • You tried CURLOPT_SSL_VERIFYPEER, how about with CURLOPT_SSL_VERIFYHOST for the purpose of debugging only? Commented Aug 19, 2015 at 21:35
  • @Scuzzy I have tested, no difference. Commented Aug 19, 2015 at 21:43
  • Are you testing the CLI version from the same server as the PHP version? Commented Aug 19, 2015 at 21:44
  • @Willian No, not behind a proxy, we are behind a firewall, but that's the same for CLI. Commented Aug 19, 2015 at 22:03

2 Answers 2

3

Your php code is fine. Do a curl_getinfo($ch) and curl_error($ch) aftercurl_exec to see the response code returned by the server.

Update: I tested ashleydirect.com SSL certificate and it supports only TLS 1.0. So make sure your php version supports TLSv1.0.

Sign up to request clarification or add additional context in comments.

4 Comments

Correct, no response code, I posted the information above.
@Kerry, please try to add print_r(curl_error($ch)) command after exec.
Added to the info above, and here: Unknown SSL protocol error in connection to www.ashleydirect.com:443
Wow -- that was it, TLS 1.0 -- specifically. Thank you so much -- how did you test it and figure out what it supported (for future reference for myself)
2

It works fine for me, both the command line without -k and the PHP code.

If for some reason it times out you can set a bigger timeout:

// if it times out on establishing the connection
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);   // seconds
// if it times out while waiting for the response
curl_setopt($ch, CURLOPT_TIMEOUT, 60);          // seconds

Also, the call curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false) is usually accompanied by:

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

to get the complete effect.

5 Comments

It is timing out after 60 seconds, I tried with VERIFYHOST as well, same thing. Good to know it works for you...
The command line curl, with or without -k starts almost instantly and needs about 12 seconds to download the file. This pastie contains the print_r(curl_getinfo($ch)); after the PHP version completed the transfer. I'm using the exact code you posted. It is probably a connection issue on your side.
Thank you -- do you have any idea what type of connection could start that? the curl -k works for me instantly as well, what would affect PHP but not CLI?
Different versions of curl; different settings; different SSL/TLS libraries. I don't know. Try different values for CURLOPT_SSLVERSION, maybe it helps.
I saw the question updates now. CURLOPT_SSLVERSION is the solution. Try the values with TLS.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.