Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

SiNi_Si's avatar

Using Laravel api route to check website status and ssl

Hello everyone, I have about 45 projects running on my server and own certbot running.

I was thinking of best way to run a cron task to check all website status and https status. My idea and just a thought is each site has an api route that I can send and ask site to do it’s own check?

This is just a thought then doing a multi thread get httpheader.

Would this be a good idea? Looking for pros and cons.

So just to give a little more info and it would be easy to apply. The 45 projects are on one laravel project with each their own db.

Thanks and interested to hear your thoughts.

Thanks Si

0 likes
2 replies
LaryAI's avatar
Level 58

To achieve the goal of checking the status and SSL of multiple websites hosted on your server, you can indeed use a Laravel API route to perform these checks. However, there are some considerations and potential improvements to this approach.

Pros and Cons

Pros:

  1. Centralized Management: You can manage the checks from a single Laravel application.
  2. Automation: Automate the process using Laravel's task scheduling.
  3. Scalability: Easily add or remove projects from the check list.

Cons:

  1. Overhead: Each site needs to expose an API endpoint, which might not be ideal for all projects.
  2. Security: Exposing an API endpoint for status checks could be a security risk if not properly secured.
  3. Complexity: Managing multiple API endpoints and ensuring they are all functioning correctly can be complex.

Suggested Approach

  1. Centralized Check from a Single Application: Instead of having each site expose an API endpoint, you can perform the checks from a single Laravel application. This application can iterate over the list of websites and perform HTTP requests to check their status and SSL.

  2. Using Laravel's Task Scheduling: Use Laravel's task scheduling to automate the process. You can create a command that performs the checks and schedule it to run at your desired interval.

  3. Using Guzzle for HTTP Requests: Use Guzzle, a PHP HTTP client, to perform the HTTP requests and check the status and SSL of each website.

Implementation

Here's a basic implementation using Laravel:

  1. Create a Command:

    First, create a new Artisan command:

    php artisan make:command CheckWebsitesStatus
    
  2. Implement the Command Logic:

    In the handle method of the command, use Guzzle to perform the checks:

  3. Schedule the Command:

    Open app/Console/Kernel.php and schedule the command:

    protected function schedule(Schedule $schedule)
    {
        $schedule->command('check:websites')->hourly();
    }
    
  4. Run the Scheduler:

    Ensure your Laravel scheduler is running. You can do this by adding the following cron entry:

    * * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1
    

This approach centralizes the status and SSL checks, reducing the need for each site to expose an API endpoint. It also leverages Laravel's built-in task scheduling to automate the process.

martinbean's avatar

@sini_si Why would a web application know the status of a SSL certificate? The SSL certificate could be renewed or revoked at any time. You should instead by generating certificates, and then storing that expiration date somewhere.

You’d be better off just having some sort of scheduled task that runs weekly and generates new SSL certificates for your websites.

Please or to participate in this conversation.