Can anybody tell me why this CURL code only works on my local server and not on live server? Tried on 3 different hosting and nothing works.
Checked everything on live 1) Curl enabled 2) PHP version is OK 3) Curl executes without any error but no result
Its been 3 days and I am not able to find any solution please help.
error_reporting(1);
set_time_limit(1500);
$fname=time().'_myfile.flv';
header('Content-type: video/x-flv');
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"$fname\"");
define('USERAGENT', "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.2; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)");
$url='http://v3.lscache5.c.youtube.com/videoplayback?sparams=id%2Cexpire%2Cip%2Cipbits%2Citag%2Calgorithm%2Cburst%2Cfactor&fexp=914010%2C907605&algorithm=throttle-factor&itag=34&ip=112.0.0.0&burst=40&sver=3&signature=D51A660BDF83B54B3584425DBE8930D5D0F805E1.B3FB21D0CAF625D36A17B558A0A653F20788B49F&expire=1313503200&key=yt1&ipbits=8&factor=1.25&id=1cacd26a9913e4ec';
$ch = curl_init() or die("Error");
curl_setopt($ch, CURLOPT_USERAGENT, USERAGENT);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
if(curl_exec($ch) === FALSE)
{
die("Curl failed: " . curl_error($ch)); // Never goes here
}
curl_close($ch);
?>
I had this issue for several days, was not able to find any errors in the PHP and the cURL response seemed to come back completely null. Finally found suggested code to put into the cURL request
if (curl_exec($curl) === FALSE) {
die("Curl Failed: " . curl_error($curl));
} else {
return curl_exec($curl);
}
Adding this finally gave me an error in the PHP which was:
Curl Failed: SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
Searching that error on SO gave me this: HTTPS and SSL3_GET_SERVER_CERTIFICATE:certificate verify failed, CA is OK
Which lead me to add code to my cURL request that essentially disables the SSL verification.
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
I'm not working w/ my server admin to find a better solution because I don't know if this workaround is so good, but for now this works.
Do a curl_getinfo($ch)
after exec to see the response code returned by the server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With