使用 composer 安装失败
本人 Windows 机,今天准备安装 horizon 拓展包时发现安装不上。
composer require "laravel/horizon:~3.1"
在网上一番搜索才知道,是因为 horizon 这个拓展包依赖 PHP 的 pcntl 拓展。所以正常情况是安装不上的。
解决方法一:
在 composer.json 中 配置如下:
"config": {"platform": {"ext-pcntl": "7.2","ext-posix": "7.2"}}
这种方法是通过在 json 中配置 pcntl 来骗过 composer 安装 horizon 。
解决方法二:
在 composer require 后加上 --ignore-platform-reqs 参数:
composer require "laravel/horizon:~3.1" --ignore-platform-reqs
这种方法是直接告诉 composer 忽略 pcntl。在使用的过程中,这种方法有一点不方便,就是以后每次安装该拓展,都要加上 --ignore-platform-reqs 。十分麻烦。
php artisan horzion 报错
今天在学习 L02 课程的时候,安装完 horizon 后,打算使用 php artisan horizon 结果发现用不了,找了一圈答案,于是有了这篇文章。
报错信息
首先来看看报错信息,下面是执行 php artisan horizon 的结果。
Symfony\Component\Debug\Exception\FatalThrowableError : Call to undefined function Laravel\Horizon\Console\pcntl_async_signals()at D:\Git\LaravelCourse\LaravelTow\vendor\laravel\horizon\src\Console\HorizonCommand.php:5551| );52|53| $this->info('Horizon started successfully.');54|> 55| pcntl_async_signals(true);56|57| pcntl_signal(SIGINT, function () use ($master) {58| $this->line('Shutting down...');59|Exception trace:1 Laravel\Horizon\Console\HorizonCommand::handle(Object(Laravel\Horizon\Repositories\RedisMasterSupervisorRepository))D:\Git\LaravelCourse\LaravelTow\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:322 call_user_func_array()D:\Git\LaravelCourse\LaravelTow\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:32Please use the argument -v to see more details.
问题所在
可以看到是 pcntl_async_signals() 这个函数出现了问题,前后找了一圈,才知道 pcntl 这个 PHP 扩展不支持 非 Unix 类系统 。
如何解决
找了很多资料,也没有找到合适的解决方法。
目前比较好的解决方法为:继续使用 php artisan queue:listen 来监听,效果是一样的。只不过得一直让改进程保持常驻。
最后
还是使用 Homestead 吧!!!
