# Using slim 4 app in CLI mode

**URL:** <https://discourse.slimframework.com/t/using-slim-4-app-in-cli-mode/3669>\
**Category:** Questions\
**Created:** [November 20, 2019, 4:32pm UTC](https://discourse.slimframework.com/t/using-slim-4-app-in-cli-mode/3669 "2019-11-20T16:32:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sidbenac](https://avatars.discourse-cdn.com/v4/letter/s/ebca7d/32.png) [@sidbenac](https://discourse.slimframework.com/u/sidbenac)\
**Post date:** [November 20, 2019, 4:32pm UTC](https://discourse.slimframework.com/t/using-slim-4-app-in-cli-mode/3669/1 "2019-11-20T16:32:45Z")

</div>

Hi,

Did someone succeeded to run slim 4 on CLI ?

I need to setup cronjobs for my app to run on the cli, but I am unable to use do it,

I am using the SLIM 4 squeleton app from github.

thank you

---

<div class="post-metadata">

**Author:** ![pedropereira](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/pedropereira/32/982_2.png) [@pedropereira](https://discourse.slimframework.com/u/pedropereira)\
**Post date:** [November 20, 2019, 5:00pm UTC](https://discourse.slimframework.com/t/using-slim-4-app-in-cli-mode/3669/2 "2019-11-20T17:00:50Z")

</div>

Hi 🙂

Slim is wired as an HTTP app, it doesn’t grab CLI arguments, only server request ones… I think.

But you could easily manually grab the arguments you need from your CLI request and create a fake PSR-7 Request with those arguments to inject on $app-\>run().

Never tried but seems possible.

---

<div class="post-metadata">

**Author:** ![sidbenac](https://avatars.discourse-cdn.com/v4/letter/s/ebca7d/32.png) [@sidbenac](https://discourse.slimframework.com/u/sidbenac)\
**Post date:** [November 20, 2019, 6:20pm UTC](https://discourse.slimframework.com/t/using-slim-4-app-in-cli-mode/3669/3 "2019-11-20T18:20:55Z")

</div>

Thx for the quick answer Pedropereira 🙂

Do you have a way or an example to do that ? I can’t figure it out ☹

thx

---

<div class="post-metadata">

**Author:** ![odan](https://avatars.discourse-cdn.com/v4/letter/o/9de053/32.png) [@odan](https://discourse.slimframework.com/u/odan)\
**Post date:** [November 20, 2019, 6:26pm UTC](https://discourse.slimframework.com/t/using-slim-4-app-in-cli-mode/3669/4 "2019-11-20T18:26:33Z")

</div>

Hi @sidbenac

Like @pedropereira said, you could invoke the routes via the console. To achive this, you could create a mocked request object and invoke the `$app->handle($request)` method. The downside is that the console output is not optimized for the CLI. Passing and mapping console input parameters is also not so easy.

You could implement a [symfony/console](https://symfony.com/doc/current/components/console.html) command for your Slim application. I have prepared an example for Slim 4 here:

- [https://github.com/odan/slim4-skeleton/blob/master/bin/console.php](https://github.com/odan/slim4-skeleton/blob/master/bin/console.php)
- [https://github.com/odan/slim4-skeleton/tree/master/src/Console](https://github.com/odan/slim4-skeleton/tree/master/src/Console)
