没有不值得去解决的问题,也没有不值得去学习的技术!

Error When Installing laravel/horizon via Composer: Package laravel/horizon at version ~5.6 has requirements incompatible with your PHP version, PHP extensions and Composer version

When installing laravel/horizon via Composer, an error occurs: Package laravel/horizon at version ~5.6 has requirements incompatible with your PHP version, PHP extensions and Composer version.

1. When installing laravel/horizon via Composer, an error occurs: Package laravel/horizon at version ~5.6 has requirements incompatible with your PHP version, PHP extensions and Composer version. See Figure 1.

When installing laravel/horizon via Composer, an error occurs: Package laravel/horizon at version ~5.6 has requirements incompatible with your PHP version, PHP extensions and Composer version.
Figure 1
Plaintext

PS E:\wwwroot\larabbs> composer require "laravel/horizon:~5.6"


  [InvalidArgumentException]
  Package laravel/horizon at version ~5.6 has requirements incompatible with your PHP version, PHP extensions and Com
  poser version:
    - laravel/horizon v5.7.17 requires ext-pcntl * but it is not present.
    - laravel/horizon v5.7.17 requires ext-posix * but it is not present.


require [--dev] [--dry-run] [--prefer-source] [--prefer-dist] [--prefer-install PREFER-INSTALL] [--fixed] [--no-suggest] [--no-progress] [--no-update] [--no-install] [--no-scripts] [--update-no-dev] [-w|--update-with-dependencies] [-W|--update-with-all-dependencies] [--with-dependencies] [--with-all-dependencies] [--ignore-platform-req IGNORE-PLATFORM-REQ] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--apcu-autoloader-prefix APCU-AUTOLOADER-PREFIX] [--] []...

PS E:\wwwroot\larabbs>

2. Based on the prompt, I tried to install the PHP extensions: pcntl and posix, but pcntl is not available on Windows. See Figure 2.

Based on the prompt, I tried to install the PHP extensions: pcntl and posix, but pcntl is not available on Windows.
Figure 2

3. I finally decided to install it on my local Windows machine first, since I can just run it on Linux later. I enabled the option: –ignore-platform-reqs to ignore all platform requirements (php, hhvm, lib-* and ext-*) and force the installation, even if the local machine does not meet these requirements. The installation succeeded. See Figure 3.

I finally decided to install it on my local Windows machine first, since I can just run it on Linux later. I enabled the option: --ignore-platform-reqs to ignore all platform requirements (php, hhvm, lib-* and ext-*) and force the installation, even if the local machine does not meet these requirements. The installation succeeded.
Figure 3
Plaintext

PS E:\wwwroot\larabbs> composer require "laravel/horizon:~5.6" --ignore-platform-reqs
./composer.json has been updated
Running composer update laravel/horizon
Loading composer repositories with package information
Updating dependencies
Lock file operations: 1 install, 0 updates, 0 removals
  - Locking laravel/horizon (v5.7.17)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
  - Downloading laravel/horizon (v5.7.17)
  - Installing laravel/horizon (v5.7.17): Extracting archive
1 package suggestions were added by new dependencies, use `composer suggest` to see details.
Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead.
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: barryvdh/laravel-debugbar
Discovered Package: facade/ignition
Discovered Package: fruitcake/laravel-cors
Discovered Package: intervention/image
Discovered Package: laravel/horizon
Discovered Package: laravel/sail
Discovered Package: laravel/sanctum
Discovered Package: laravel/tinker
Discovered Package: laravel/ui
Discovered Package: mews/captcha
Discovered Package: mews/purifier
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Discovered Package: overtrue/laravel-lang
Discovered Package: summerblue/generator
Discovered Package: summerblue/laravel-active
Package manifest generated successfully.
83 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
> @php artisan vendor:publish --tag=laravel-assets --ansi --force
Copied Directory [\vendor\laravel\horizon\public] To [\public\vendor\horizon]
Publishing complete.
PS E:\wwwroot\larabbs>

4. After the installation is complete, I opened larabbs.local/horizon in the browser to access the dashboard. It works as expected. See Figure 4.

After the installation is complete, I opened larabbs.local/horizon in the browser to access the dashboard. It works as expected.
Figure 4

5. However, I cannot use the horizon command to start the queue system and task monitoring. It throws an error: Call to undefined function Laravel\Horizon\Console\pcntl_async_signals(). See Figure 5.

However, I cannot use the horizon command to start the queue system and task monitoring. It throws an error: Call to undefined function Laravel\Horizon\Console\pcntl_async_signals()
Figure 5
Plaintext

PS E:\wwwroot\larabbs> php artisan horizon
Horizon started successfully.

   Error

  Call to undefined function Laravel\Horizon\Console\pcntl_async_signals()

  at E:\wwwroot\larabbs\vendor\laravel\horizon\src\Console\HorizonCommand.php:48
     44▕         );
     45▕
     46▕         $this->info('Horizon started successfully.');
     47▕
  ➜  48▕         pcntl_async_signals(true);
     49▕
     50▕         pcntl_signal(SIGINT, function () use ($master) {
     51▕             $this->line('Shutting down...');
     52▕

  1   E:\wwwroot\larabbs\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:36
      Laravel\Horizon\Console\HorizonCommand::handle(Object(Laravel\Horizon\Repositories\RedisMasterSupervisorRepository))

  2   E:\wwwroot\larabbs\vendor\laravel\framework\src\Illuminate\Container\Util.php:40
      Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
PS E:\wwwroot\larabbs>

6. Later, when installing other extensions, I also need to add the parameter: –ignore-platform-reqs, otherwise it will throw an error. However, I strongly recommend not using this parameter, as it will cause unpredictable problems later. See Figure 6.

Later, when installing other extensions, I also need to add the parameter: --ignore-platform-reqs, otherwise it will throw an error. However, I strongly recommend not using this parameter, as it will cause unpredictable problems later.
Figure 6
Plaintext

PS E:\wwwroot\larabbs> composer require "spatie/laravel-permission:~3.0"
./composer.json has been updated
Running composer update spatie/laravel-permission
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - laravel/horizon is locked to version v5.7.17 and an update of this package was not requested.
    - laravel/horizon v5.7.17 requires ext-pcntl * -> it is missing from your system. Install or enable PHP's pcntl extension.

To enable extensions, verify that they are enabled in your .ini files:
    - C:\php-7.4.27\php.ini
You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.

Installation failed, reverting ./composer.json and ./composer.lock to their original content.
PS E:\wwwroot\larabbs> git status
On branch main
Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean
PS E:\wwwroot\larabbs> composer require "spatie/laravel-permission:~3.0"  --ignore-platform-reqs
./composer.json has been updated
Running composer update spatie/laravel-permission
Loading composer repositories with package information
Updating dependencies
Lock file operations: 1 install, 0 updates, 0 removals
  - Locking spatie/laravel-permission (3.18.0)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
  - Downloading spatie/laravel-permission (3.18.0)
  - Installing spatie/laravel-permission (3.18.0): Extracting archive
Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead.
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: barryvdh/laravel-debugbar
Discovered Package: facade/ignition
Discovered Package: fruitcake/laravel-cors
Discovered Package: intervention/image
Discovered Package: laravel/horizon
Discovered Package: laravel/sail
Discovered Package: laravel/sanctum
Discovered Package: laravel/tinker
Discovered Package: laravel/ui
Discovered Package: mews/captcha
Discovered Package: mews/purifier
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Discovered Package: overtrue/laravel-lang
Discovered Package: spatie/laravel-permission
Discovered Package: summerblue/generator
Discovered Package: summerblue/laravel-active
Package manifest generated successfully.
84 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
> @php artisan vendor:publish --tag=laravel-assets --ansi --force
Copied Directory [\vendor\laravel\horizon\public] To [\public\vendor\horizon]
Publishing complete.
PS E:\wwwroot\larabbs>

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系