I'm trying to query data from another website by using PHP curl_setopt as below function, But I don't know to valid when my partner sever get any error as below description.
[Server Error 5xx]
500="Internal Server Error"
501="Not Implemented"
502="Bad Gateway"
503="Service Unavailable"
504="Gateway Timeout"
505="HTTP Version Not Supported"
public function getNumber() {
$url = "http://website/PalmHallServer_kl/!queryLuckNumberRecordByPeriods.action";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: Json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$contents = curl_exec($ch);
$res = false;
if ($contents) {
$res = TRUE;
} else {
$res = FALSE;
}
echo json_encode(array("res" => $res, 'data' => $contents));
}
First tell curl that you want to see the headers returned
curl_setopt($ch, CURLOPT_HEADER, true);
Then you can get Response code using
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
To see all the information contained in the response headers you can do
print_r(curl_getinfo($ch));