Contents

PHP 错误解决经验

查看日志

查看可疑的僵尸进程

1
ps aux|grep php

laravel中

打印sql

1
2
$fullSql = vsprintf(str_replace('?', '%s', $query->toSql()), $query->getBindings());
dd($fullSql);

重启队列,清除缓存

1
2
3
4
5
6
7
8
9
# php artisan schedule:finish {id}
php artisan config:clear
php artisan view:clear
php artisan cache:clear
composer dump-autoload
# laravel9中才有
# php artisan schedule:clear-cache

php artisan queue:restart

查看队列积存

  • 古老版queue:work常驻内存的方法:forever,现在一般都是supervisor
1
forever start -c php artisan queue:work --tries=1 --queue=default,high
  • 查看队列积存,先进入redis-cli;默认队列,可以在 config/queue.php 中查看
1
2
3
4
# default队列的长度
llen queues:default
# default队列前10条job
lrange queues:default 0 10

手动执行定时脚本中的命令

1
php artisan 命令签名

重启php,nginx,cron,supervisor等服务

关于supervisor服务,参考Supervisor的使用

关于cron,查看定时脚本的用户

1
2
3
4
5
sudo crontab -l -u 用户名

sudo service cron restart

* * * * * php7.4 /mnt/g/Workplace/explore/php/blog/artisan schedule:run >> /dev/null 2>&1

关于重启fpm进程

  • 现在fpm主进程中找到保存pid的文件
https://static.duan1v.top/images/20230816102552.png
  • 然后使用SIGUSR2重启
1
2
3
4
kill -SIGUSR2 `cat /www/server/php/72/var/run/php-fpm.pid`

# 也可以启动时指定pid的文件
sudo /usr/sbin/php-fpm7.4 -c /etc/php/7.4/fpm/php-fpm.conf -y /run/php/php7.4-fpm.pid

关于重新加载nginx配置

1
/usr/bin/nginx -s reload

查看进程相关信息

https://static.duan1v.top/images/20230816103313.png

查看端口相关信息

1
2
3
netstat -tunlp | grep 端口号
# or
lsof -i:端口号

502 bad gateway

  • 本地wsl有时候会莫名其妙报这个
  • 先重启nginx,再重启php-fpm

清理服务器磁盘

1
sudo du -sh /home/ubuntu/* | sort -rn | head
coffee