curl-and-php
SSL: couldn't create a context! Errors
Date: Wed, 14 Jan 2009 11:48:59 -0600
Hi,
We are experiencing the following error intermittently when we use the
curl multi-handle... functionality: "SSL: couldn't create a context!"
We're running Arch Linux, with Apache 2.2.10 and the latest Pacman
modules for PHP (5.2.7-2), cURL (7.19.2), and OpenSSL (0.9.8j).
Here's how our code is written (based on examples from php.net)
// Create the multiple cURL handle
$mh = curl_multi_init();
foreach($requestSet as $requestItem)
{
curl_multi_add_handle($mh, $requestItem['handle']);
}
$running = null;
// Execute the handles
do {
$mrc = curl_multi_exec($mh, $running);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
while ($running && $mrc == CURLM_OK) {
if (curl_multi_select($mh) != -1) {
do {
$mrc = curl_multi_exec($mh, $running);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
}
}
foreach($requestSet as $requestItem)
{
$ch = $requestItem['handle'];
$headers = curl_getinfo($ch);
if ($headers['http_code'] == 200)
{
$response = curl_multi_getcontent($ch);
if(strlen($response) > 0)
{
// Handle Good Response
}
else
{
// Error
}
}
else
{
// Error
}
curl_multi_remove_handle($mh, $ch);
}
curl_multi_close($mh);
Our cURL options are set as follows:
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 15); // times out after 15 secs
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // this line makes it work
under https
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); // this line makes it work
under https
curl_setopt($ch, CURLOPT_POSTFIELDS, $XMLRequest); //adding POST data
curl_setopt($ch, CURLOPT_FORBID_REUSE, TRUE); //forces closure of
connection when done
curl_setopt($ch, CURLOPT_POST, 1); //data sent as POST
Most of our connections are to https:// addresses, and the failures
occur even if we're processing one handle at a time. The weird thing is
that these errors occur very regularly on one of our servers, but only
once about every 30 minutes on our much faster (and busier) server which
runs Red Hat Enterprise 5.0, so the frequency appears to be a function
of machine speed.
Has anyone else experienced this sort of behavior when using the
multi-handle functionality? Or are we doing something wrong in our code?
Thanks,
Dave
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2009-01-14