-2
Hello. I am using LARAVEL.
I have a div that displays whether the site is ON or OFF. Using the curl_info function, the url is passed and then the function returns the site status.
I would like this div to be constantly updated to check when the site gets OFF. How to update only this div and not the whole site with Javascript?
PHP
public function curl_info($url){
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_HEADER, 1);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 1);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1 );
$content = curl_exec( $ch );
$info = curl_getinfo( $ch );
if ($info['http_code']==200 ) {
return "ON";
} else {
return "OFF";
}
}
<div class="col-3 text-center font-weight-bold border border-light {!! app(App\Http\Controllers\monitController::class)->curl_info('http://google.com') !!}" id="meupc">
SITE
<p>{!! app(App\Http\Controllers\monitController::class)->curl_info('http://google.com') !!}</p>
</div>
setInterval + AJAX
– Valdeir Psr
What is your question? How to run the method from time to time, how to update the div or how to do Curl?
– tvdias
Just to confirm, you change the div so you know? $('#suaDiv'). text('content') OR in JS: Document.getElementById("bla"). innerHTML = "new content of div";
– Ewerton Dutra