0

I have a curl request, it working fine in my localhost, I have uploaded it to server but it hangs and end with error 500 internal server error. If remove the line echo $output = curl_exec($ch); It works fine.

$url = "https://someserver.com/api/";
$username = "some_user";
$password = "some_apss";
if(!extension_loaded('curl')){
    die("Curl extension not loaded");
}
if(!function_exists('curl_init')){
    die("curl_init not found");
}

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);     
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); 
echo $output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);`
6
  • of course it works if you remove the echo $output = curl_exec($ch); part, because the request is not executed anymore. check the server you are making the request to in a browser and see if it works Commented Sep 18, 2012 at 8:55
  • Try writing $output = curl_exec($ch); echo $output Commented Sep 18, 2012 at 8:55
  • the script is working fine in localhost :( Commented Sep 18, 2012 at 8:56
  • @MiqdadAli Does it work when you access the same url in a browser? Commented Sep 18, 2012 at 8:57
  • @shiplu.mokadd.im still issue is there... Commented Sep 18, 2012 at 8:58

3 Answers 3

1

It's a server side issue. Not this script's fault.

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

1 Comment

Doesn't really matter, the error is server-side. You won't find anything in this script. Check the error logs from the server.
0

It maybe that the curl extension installed on the server with the script isn't compiled with ssl support. Execute the folowing code on the server and post back the results:

<?php
    $version = curl_version();
    $ssl_supported= ($version['features'] & CURL_VERSION_SSL);
    echo $ssl_supported == CURL_VERSION_SSL;

it should output 1. if not you have to install the ssl suport for curl

Comments

0

That was the issue with my server port. That port was closed. After opening the port its working perfect. Thank you all

Comments

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.