问题描述:
?? 拿Phalcon 官方的小例子入门Phalcon时,发现一个很奇怪的问题:涉及到 models 的操作均无法正常执行。models下面定义了一个 Users 类,IndexController 中的 indexAction 使用了 Users::find() 方法,SignupController 中的registerAction创建了一个 Users 类型的对象。 ??浏览器中访问 localhost/index与 lcoalhost/signup/register时都报错502 Bad Gateway。并且signup中只要U大写,localhost/signup便不能正常访问。
环境: ??Ubuntu 20.04.2 LTS ??php 7.4.3 (通过apt安装) ??nginx 1.18.0 ??php 7.4-fpm及扩展若干 (包括php-pear) ??phalcon4 (通过添加apt source安装) ??phalcon4采用官方给出的Ubuntu安装方案
原因查找:
查Log
NGINX: recv() failed (104: Connection reset by peer) while reading response header from upstream
PHP-FPM: WARNING: [pool www] child xxxx exited with code 1 after 0.xxxxx seconds from start
child异常退出导致连接重置,可见问题不在NGINX,而在PHP这边。这时联想到在安装Phalcon时,最初使用pecl安装失败(php-pear版本1.10.9),频繁报错
Notice: Trying to access array offset on value of type bool in PEAR/REST.php on line 187
PHP Notice: Trying to access array offset on value of type bool in /usr/share/php/PEAR/REST.php on line 187
有一个大胆的猜想:问题出在Phalcon上,经过验证也确实如此!
解决方案:
重新编译安装Phalcon 采用pecl安装,由于之前添加了安装源并更新了php,因此备份配置之后删除之前新安装的源,重新再安装一遍。
apt purge php-common php7.4-common
apt autopurge
apt clean
apt update
apt install php7.4
安装依赖与Phalcon
wget https://pear.php.net/go-pear.phar
apt install php7.4-xml php7.4-dev
apt purge php-pear
sudo php go-pear.phar
pecl channel-update pecl.php.net
pecl uninstall PSR
pecl install PSR
pecl install Phalcon
编译完成后,在配置文件中添加psr与phalcon
vim /etc/php/7.4/mods-available/phalcon.ini
; configuration for php phalcon module
; priority=50
[phalcon]
extension = phalcon.so
; ----- Options to use the Phalcon Framework
; phalcon.db.escape_identifiers = On
; phalcon.db.force_casting = Off
; phalcon.orm.events = On
; phalcon.orm.virtual_foreign_keys = On
; phalcon.orm.column_renaming = On
; phalcon.orm.not_null_validations = On
; phalcon.orm.exception_on_failed_save = Off
; phalcon.orm.enable_literals = On
; phalcon.orm.late_state_binding = Off
; phalcon.orm.enable_implicit_joins = On
; phalcon.orm.cast_on_hydrate = Off
; phalcon.orm.ignore_unknown_columns = Off
; phalcon.orm.update_snapshot_on_save = On
; phalcon.orm.disable_assign_setters = Off
; phalcon.orm.resultset_prefetch_records = Off
; phalcon.orm.cast_last_insert_id_to_int = Off
vim /etc/php/7.4/mods-available/psr.ini
The PSR extension is required to be loaded before Phalcon. Please ensure that it is available in your system
; priority=15
[psr]
extension = psr.so
enable mod
sudo phpenmod -v 7.4 -s ALL psr phalcon
大功告成!!!
|