To use the fsockopen
, you need to remove the schema (http://
) and the bar at the end.
Example:
$host = 'pt.stackoverflow.com';
$conectado = fsockopen($host, 80);
if (is_resource($conectado)) {
print 'online';
}else{
print 'offline';
}
Alternatives
Beyond the fsockpopen
, you can also use fopen
and curl
.
Example with fopen
:
$host = '/';
$conectado = fopen($host, 'r');
@$result = @stream_get_meta_data($conectado);
if (is_resource($conectado) && strpos($result['wrapper_data'][0], "200") !== false) {
print 'online';
}else{
print 'offline';
}
Example with curl
:
$host = 'http://answall.com:80';
ob_start();
$ch = curl_init($host);
curl_exec($ch);
$info = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
ob_end_clean();
if( $info === 200 ) {
echo "Offline";
} else {
echo "Offline";
}
You are using
curl_init
? Or you know if your page is returning the status 200?– Valdeir Psr
'Cause it’s I tried to make via CURL plus my trial hosting doesn’t allow I guess.
– Wesley Rodrigues
I want to send a command to a page to return the value 200.
– Wesley Rodrigues
Utilize curl_getinfo
– Valdeir Psr
Neither curl_getinfo(); as tbm does not appear phpinfo();
– Wesley Rodrigues
error 404 on page.
– Wesley Rodrigues
Have you tried to verify the answer with the stream_get_meta_data ?
– Valdeir Psr
How do I do that?
– Wesley Rodrigues
If possible [Edit] your question and add how you are doing. It becomes easier to show a solution.
– Valdeir Psr
So I changed, I tried to be as clear as I could.
– Wesley Rodrigues
In my system only returned at 14:40 on the other verification system nor crashed.
– Wesley Rodrigues