Search code examples
phpslimphp-7.2swoole

Swoole server only can be used in PHP CLI mode


I am using Swoole server and slim framework, especially this library:

Slim Swoole Link

I have followed the tutorial, and gives me this error:

Fatal error: Swoole\Server::__construct(): swoole_server only can be used in PHP CLI mode. in /Users/powermilk/Documents/Proyectos/prueba/public/index.php on line 48

the line 48 has the below code:

$http = new swoole_http_server("0.0.0.0", 8081);

I don't understand why happens this if I quit the library code everything works nice, but I am not able to run slim with Swoole.

The server is running over Nginx.


Solution

  • I'm the writer of the library. Yes, you have to create your "front controller"ish file and execute it from CLI. Sort of, from terminal, "php name_of_your_file.php" and leave it running.