How to work use cronjobs with slimphp


Hi all, I have an issue and I would like to know how to best approach this. I need to create some cronjobs on the server for my slimphp api. I have tried to use wget (which I have to use) to access a file at a specific path

i.e. wget -q -O - ""

The folder structure I have is as follows


I would like to be able to run that cronjob using wget. How can I navigate my folder path structure via the url to reach that path? I understand I may need to allow /scripts/php/admin/* in the “passthrough” section of the middleware.php file but I tried that and it is not working


    $container['JwtAuthentication'] = function ($container) {
        return new JwtAuthentication([
            'path'        => '/',
            'passthrough' => [
            'secret'      => getenv('JWT_SECRET'),
            'logger'      => $container['logger'],
            'error'       => function ($request, $response, $arguments) {
                return $response
                    ->withHeader('Content-Type', 'application/json');
            'callback' => function ($request, $response, $arguments) use ($container) {

Also am I going about this the wrong way? Should a route be used for this and then I have a class that is essentially going to be responsible for whatever I want that cronjob to do and then use wget to hit that route (while declaring a pass through option)


Calling a cronjob script via a URL can be problematic, because of timeouts etc…

It would be better to add a crontab task and call the php script directly:

Edit crontab file:

crontab -e

Add a crontab command (1x per minute)

* * * * * /usr/bin/php /var/www/some/path/cronjob.php

Crontab – Quick Reference


I agree with @odan that calling a PHP script for doing a cron-like operation is better off being done server-side.

But if you really want to get something PHP-like working, then I suggest PHP Quartz (based on Java Quartz library).

I don’t have experience with the PHP implementation but I have used the Java version and it is quite nice. YMMV.


Hey guys thanks for the reply!

So part of the problem is I am using a service called serverpilot which I used to set up my Digital Ocean droplet and they recommend you use wget for cron jobs because running the file directly may not work

This is why I am trying to find a way to access the url


I am not sure if this will help you, but I use “curl” to call cron URLs and it works just fine.


Thanks Lobos,

I just ended up using command line calling php. The script worked when I manually ran it so I will be able to tell next month on the 1st when it runs if it worked. Thanks for the help