Curl php ssl timeout timeout

I found this code on the Internet and I changed it for my use, I'm not sure what I am doing wrong here, I get this error Twisting error: SSL connection timeout Part of the login is successful, but the search does not work with me. can someone help me with it please?

<?php
//create array of data to be posted
$post_data['username'] = 'user';
$post_data['password'] = 'log';
$post_data['cmd'] = 'log';

//create array of data to be posted
foreach ( $post_data as $key => $value) {
    $post_items[] = $key . '=' . $value;
}
//create the final string to be posted using implode()
$post_string = implode ('&', $post_items);
//create cURL connection
$curl_connection =
  curl_init('https://sie.com');
//set options
///curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 3990);

curl_setopt($curl_connection, CURLOPT_USERAGENT,
  "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");

curl_setopt($curl_connection, CURLOPT_HTTPHEADER, array(
    'Connection: Keep-Alive',
    'Keep-Alive: 300'
));

curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
//set data to be posted
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
//perform our request
$result = curl_exec($curl_connection);
//show information regarding the request

//print_r(curl_getinfo($curl_connection));
//echo curl_errno($curl_connection) . '-' .
  //              curl_error($curl_connection);
//close the connection
//curl_close($curl_connection);


echo $result."\n";


$post_data1['cmd'] = 'Viewr';
$post_data1['search'] = 'test';



foreach ( $post_data1 as $key => $value1) {
    $post_items1[] = $key . '=' . $value1;
}
$post_string1 = implode ('&', $post_items1);
echo $post_string1."\n";
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT,
  "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
//set data to be posted
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
//perform our request
$result1 = curl_exec($curl_connection);
//show information regarding the request
//$result1 =1;
//close the connection
//curl_close($curl_connection);
if ($result1)
echo "ok \n\n";
else
echo "nok\n";
if(curl_errno($curl_connection))
{
    echo 'Curl error: ' . curl_error($curl_connection)."\n";
}
echo($post_string1);
echo $result1."\n";


curl_close($curl_connection);


?>
+5
source share
3 answers

Try adding this one (but don't leave this option in production!) :

curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);

If it works afterwards, this is because CURL cannot negotiate an SSL certificate.

Follow this guide to learn how to get a CA certificate: http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/

- , , curl_exec(), curl_copy_handle();, .

, , , cURL curl_init($url);.

+4

, , SSL, , ( ). "CURLOPT_SSL_VERIFYHOST". . , .

<?php
//create array of data to be posted
$post_data['username'] = 'user';
$post_data['password'] = 'log';
$post_data['cmd'] = 'log';

//create cURL connection
$curl_connection = curl_init();
//set options
curl_setopt($curl_connection,CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($curl_connection,CURLOPT_SSL_VERIFYPEER, false);

//...

curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_data);//it can accept associative arrays

//...

?>
0

, SSL connection timeout.

php.ini , -, OpenSSL, , :

;extension=php_openssl.dll

, .

extension=php_openssl.dll

Now that OpenSSL is turned on (this is a parameter on Windows, it should look like Linux / Mac), and after rebooting my Apache server I can finally execute my cURL request without any errors!

0
source

All Articles