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. :/
It seems like you may have remote allow_url_fopen not enabled.
Put this at the beginning of your script:
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:
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.