1

I have a problem with my server setting I guess. I have a code which fetches code from another server. I don't know why, but the code is not working with my VPS, but it is working with a simple shared hosting account...

Here is the code:

$post = array(
      'KEY' => 'somekey',
      'format' => 'xml'
    );


    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'xxxxxxxxxx.com' . http_build_query($post));
    curl_setopt($ch,  CURLOPT_RETURNTRANSFER, TRUE);
    $response = curl_exec($ch);
    $xml_obj = simplexml_load_string($response);
    $json = json_encode($xml_obj);
    $array = json_decode($json, true);
    curl_close($ch);

It is working like a charm if I run it on my shared hosting server, but it just have some problem (which it does NOT output) and the script does not run. I have tested that I got 1 (true) for this statement: $json = json_encode($xml_obj); But not for any further code. So there might be somewhere the the problem.

I have also checked if xml DOM is enabled, and it is. I have also checked CURL and json, and both of them are enabled.

Can someone help me? I can't do anything without error messages, and I cannot figure out what could be the problem. :/

0

1 Answer 1

1

It seems like you may have remote allow_url_fopen not enabled. Put this at the beginning of your script:

ini_set("allow_url_fopen", 1);

To enable curl_exec, you need to modify your php.ini and remove it from the last of disallowed functions. To find out your php.ini, you can call this at the beginning of your script once:

phpinfo(); die();

That will tell you which php.ini file to use (look for the php.ini string). Once you modify php.ini, you will need to restart your web server.

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

5 Comments

Could you please elaborate what is that and how could I enable it?
Try that line, if it works for you after you put it in, then you can modify your php.ini to always allow it.
It is working now I got antoher problems: "curl_exec() has been disabled for security reasons" How can I enable it?
For that you're going to have to modify your php.ini file and remove curl_exec from the list of disallowed functions.Edit: I modified the answer to put all the required information. Curious, who is your VPS host (I'm in the market for one myself right now)?
Man! I owe you one :) Very much thanks for your help. It is working now :) Thumbs up for this guy :)

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.