0

I am having a problem Here

<?php 
        include('smsconfig.php');
        include("SMTPconfig.php");
        include("dbconnect.php");

        define("SITE_URL", "http://gf2fyu.blah.com");
        $GLOBAL_REST_URL = "gf2fyu.domain.com/organization/";

        $headers = array(
                        'X-MYDOMAIN-Secret:VuFlRQv40SUp0y1AXflMD0hWw8ZiiTu08f9ZXc0AYFc=',
                        'Content-Type: application/json; charset=UTF-8',
                        'Accept: application/json; charset=UTF-8',
        );
        //$json = array2json($ages);
        $curl_handle=curl_init();
        curl_setopt($curl_handle,CURLOPT_URL,$GLOBAL_REST_URL);
        curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
    //    curl_setopt($curl_handle, CURLOPT_POSTFIELDS,$json);
        curl_setopt($curl_handle, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
        $buffer = curl_exec($curl_handle);
        curl_close($curl_handle);
        $getit =  json_decode($buffer, true);
        $smskey =  substr(number_format(time() * rand(),0,'',''),0,5);
        print_r($getit);
?>

The above code working fine for me if i am running it on my local server and mozila REST

client but whenever i am trying to put this code on production version

this code is not hitting the rest server .

Please tell me what is the problem here ?

I am using the same header in MOzila also it is working fine

I am running Nginx

7
  • Many servers have curl disabled. Have you tried file_get_contents()? Commented Oct 13, 2012 at 10:06
  • are there any exceptions thrown? Commented Oct 13, 2012 at 10:06
  • What do you mean "its not hitting server"? If you can't connect to the server, the code is moot. If you're hitting the page, but it's coming up blank, it's likely because curl is disabled and you're getting an error. Try commenting out the curl code to see if page loads. Commented Oct 13, 2012 at 10:08
  • @Dutchie432 I don't find replacing cURL with file_get_Contents good idea (lot of servers have allow_url_wrappers disables). Commented Oct 13, 2012 at 10:08
  • @Vyktor then alternatively, the user could find a host with curl :) I'm offering an alternative for testing. Commented Oct 13, 2012 at 10:08

1 Answer 1

1

Everything really is in the comments, but let's put it down in order.

1) Curl may not be installed in the PHP on the server. To find out, turn on error reporting (or check error logs). Alternatively, a more robust way is to check for the function. Add the following to your code (just after the includes)

if (!function_exists('curl_init')) {
     die('Curl not installed');
}

Solution: you can try file_get_contents, but as noted in comments is it generally not recommended because this is also disabled. If you need to pass headers, you can do this in the "context" (third parameter in the call - check the manual). Better option is to install curl (or get support to install it).

2) There may be a firewall enabled. You can establish this by checking curl_getinfo() and dumping the result to screen (for testing). This will tell you if it got blocked or made it through. See the manual for more info (linked above).

3) There may be an error higher up in your code that is causing problems. Check the error log, or turn on error_reporting with

error_reporting(E_ALL);
ini_set('display_errors', 'on');

Remember to remove those lines when you finally go into production, though.

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

1 Comment

You have teach me a good lesson to debug thanks but really my problem was related to my nginx server

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.