Laravel Horizon, ext-pcntl and Windows
Update 2: You may want to use Docke for your local development. You could use these Tools: https://vessel.shippingdocker.com/ or https://laragon.org/
Update: As of version 1.0.1 laravel does require ext-posix via composer.json as well. I’ve updated the post to take care of this requirement.
As I start using Laravel’s newest package Horizon (Introduced by Taylor Otwell on Medium or at laracon.us) to control app’s queues, I was annoyed due to a windows related problem, pcntl (PHP’s process controlling module). And since version 1.0.1 the posix extension is required as well, which is also not available on windows.
After creating a new Laravel 5.5 project and adding horizon I got this error:
composer require laravel/horizon Loading composer repositories with package information Updating dependencies (including require-dev) Your requirements could not be resolved to an installable set of packages. Problem 1 - laravel/horizon dev-master requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system. - laravel/horizon dev-master requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system. - Installation request for laravel/horizon dev-master -> satisfiable by laravel/horizon[dev-master]. To enable extensions, verify that they are enabled in your .ini files: - C:\dev\tools\php\php.ini You can also run php --ini inside terminal to see which files are used by PHP in CLI mode.
By lookup the error I quickly learned, pcntl doesn’t like windows at all. Therefore I needed a workaround.
Ignore all platform requirements
The simplest way to install the dependencies anyway, is to ignore all platform related requirements using the option --ignore-platform-reqs
(https://getcomposer.org/doc/03-cli.md#install)
But this is a bit hard, what happen if any another package needs a PHP module that is available for windows? Not a productive-like solution I think.
Ingore the module pctnl and posix
Composer supports using the option --ignore-platform-reqs
and additionally specifiy which packages/modules to ignore. So you can run the following command for each install/update:
composer install --ignore-platform-reqs ext-pcntl ext-posix
But then, everyone using your app needs to know that just to run some queue admin panel. Not really proportionate.
Configure ignorance in composer.json
I finnaly came up with ignoring just the pcntl module at all directly in the composer.json file, since it’s not critical to run my app, only to run horizon.
{ "config": { "platform": { "ext-pcntl": "7.1", "ext-posix": "7.1" } } }
The version of ext-pcntl and ext-posix is similar to the version of php I’m using. In my tests the version newer received any attention…
But notice: You are now responsible to install/enable pcntl on your prod server to be able to use it.
10 Comments
typo in comand
composer install –iNGore-platform-reqs ext-pcntl
need to be replaced with
composer install –ignore-platform-reqs ext-pcntl
Thank you, I’ve fixed it.
Thanks Oliver. It works like a charm…
Thanks Man 🙂 Finally Solved!
welcome man
It works, thx
It didn’t work 🙁
cannot help you with this error description… what was the error message?
It works! Thanks 😉
Welcome!