Dronax
7 months ago
111
20
Laravel

Laravel job check site if online

Posted 7 months ago by Dronax

Hello. On every post I have url a website. I need get status and check every hour if this site is online. How I can do it with queues Laravel? I have a job CheckPostSite:

public function handle()
{
    $allposts = Post::all();

    foreach($allposts as $post) {
         if($this->checkOnline($post->site_url) {
              $post->website_online = true;
              $post->save();
         }
    }
}

private function checkOnline($domain) {
    $curlInit = curl_init($domain);
    curl_setopt($curlInit,CURLOPT_CONNECTTIMEOUT,10);
    curl_setopt($curlInit,CURLOPT_HEADER,true);
    curl_setopt($curlInit,CURLOPT_NOBODY,true);
    curl_setopt($curlInit,CURLOPT_RETURNTRANSFER,true);

    //get answer
    $response = curl_exec($curlInit);

    curl_close($curlInit);
    if ($response) return true;
    return false;
}

I'm doing everything right? Or not? I have 10000+ posts in database.

Please sign in or create an account to participate in this conversation.