Using PHP I would like force a 404 error in the browser.
We are using a homegrown Load Balancer for testing and what is happening is the shared storage sometimes goes offline. The load balancer healthcheck page (example.com/health.php) checks for a 200 response. If 200, page is health, any other status code will mark the node down.
What I would like to do is have php call a file from the shared storage and check if the file exist.
If the shared storage is up and files
is the mount example.com/files/isup.htm
would generate a 200.
If the page does not exist ie. storage is down and the mount point cannot be reached 404 error.
Problem I am having using the code below:
<?php
$ch = curl_init('example.com/gdkjfh.png');
curl_exec($ch);
if (curl_errno($ch)) {
} else {
header("Location: dkjlflkjxfgkdnbcxfn.html");
}
curl_close($ch);
?>
From question: How can I create an error 404 in PHP?
<?php
$ch = curl_init('http://example.com/dfdkfh.png');
curl_exec($ch);
if (curl_errno($ch)) {
} else {
http_response_code(404);
include('my_404.php'); // provide your own HTML for the error page
die();
}
curl_close($ch);
?>
However the load balancer still see a 200 response from example.com/health.php. Also bringing the page up in a browser will generate a 200. Therefore I think what I have to do is generate a 404(or any other status code not 200) within the browser.
How can I force a 404 in the browser using php? I am trying to break the page, just like if you visit ttp://example.com/dfdkfh.png in the network console you will see a 404
No .htaccess no modify the httpd.conf