自己开发的laravel第三方composer包,由于需要使用到session,包配置成自动发现,在ServiceProvider的boot中添加了自动加载路由 loadRoutesFrom 结果死活不能正常使用。
最后各种搜索发现,原因是 “StartSession” 仅被添加到web中间件中,必须给包路由加了 [‘middleware’=>’web’]才可以正常使用session
2022年4月8日 laravel
自己开发的laravel第三方composer包,由于需要使用到session,包配置成自动发现,在ServiceProvider的boot中添加了自动加载路由 loadRoutesFrom 结果死活不能正常使用。
最后各种搜索发现,原因是 “StartSession” 仅被添加到web中间件中,必须给包路由加了 [‘middleware’=>’web’]才可以正常使用session
2022年3月24日 laravel
自定义private-channel时,避免使用private-开头的频道名,系统默认的模型认证会在频道名上自动加上‘private-’前缀,自定义频道名时,避开这规则,同时在config/channels.php里对自定义的私有频道进行登录权限验证,如:
Broadcast::channel('custom-private-channel-{id}', function ($user, $id) { if( is_numeric($id) ){ return (int) $user->id === (int) $id; }else{ return session()->getId() === $id; } });
在laravel-echo-server.json设置devMode=true查看日志,确认所有验证能正常通过后,私有频道即可监听到。
原生 http_build_query() 方法定义:
function http_build_query (object|array $data, string $numeric_prefix = "", ?string $arg_separator = "&", int $encoding_type = PHP_QUERY_RFC1738)
指定使用 PHP_QUERY_RFC3986:
laravel:
GuzzleHttp\Psr7\Query::build() 默认使用 PHP_QUERY_RFC3986
方法定义:
2022年1月8日 laravel
线上环境一但使用 php artisan config:cache 就会各种异常,最终检查原因是使用 config:cache 后env() 是无法读取 .env文件配置的。
将 config 文件之外的所有 env() 方法使用 config() 代替
如:
在 config/app.php 中添加:'force_https' => env('FORCE_HTTPS', false),
调用时使用 config('app.force_https')
PS: 通过composer引用的包不受此影响
2022年1月6日 laravel
开发环境是http的,线上环境https,导致线上资源加载http而无法加载。
大多网友遇到问题是通过给asset()加第二个参数,或使用secure_asset()代替
两个方法都要修改所有引用的blade,还有一些第三方blade重写更加麻烦,如horizon的单页面
废话少说,解决方案:
1、.env 添加ASSET_URL=xxx 与APP_URL一致,用于给asset()添加固定的https前缀
2、.env 添加 FORCE_HTTPS=true,本地环境false
3、config/app.php 添加'force_https' => env('FORCE_HTTPS', false)
4、AppServiceProvider boot() 里添加如下代码,用于解决url()生成https链接
5、AppServiceProvider register() 里添加如下代码,用于解决pjax加载https
6、测试,OK
2021年9月2日 git
wrk是一款简单的HTTP压测工具,托管在Github上,https://github.com/wg/wrk.
wrk 的一个很好的特性就是能用很少的线程压出很大的并发量. 原因是它使用了一些操作系统特定的高性能 io 机制, 比如 select, epoll, kqueue 等.
测试
2021年6月29日 PHP
Manually enabling Swoole via php.ini
On most systems Swoole can be enabled by directly editing your
configuration file, you will want to add
to the end of the file and then Swoole should be enabled.
Enabling Swoole via phpenmod
Some Linux distributions like Debian or Ubuntu use the PHP
to load PHP extensions, in this case you can use
to enable Swoole.
一般系统 都可以通过添加扩展到php.ini的方式添加swoole支持,但我用的debian10+php7.4不支持,报如下错
PHP Warning: PHP Startup: Unable to load dynamic library 'swoole' (tried: /usr/lib/php/20190902/swoole (/usr/lib/php/20190902/swoole: cannot open shared object file: No such file or directory), /usr/lib/php/20190902/swoole.so (/usr/lib/php/20190902/swoole.so: undefined symbol: php_json_exception_ce)) in Unknown on line 0
只能通过
#!/bin/bash
# Create a Swoole extension PHP ini file, letting PHP know which modules to load
$ sudo bash -c "cat > /etc/php/<PHP_VERSION>/mods-available/swoole.ini << EOF
; Configuration for Swoole
; priority=25
extension=swoole
EOF"
# Enable the Swoole PHP extension only on CLI mode
$ sudo phpenmod -s cli swoole
# Optional: Enable Swoole for specific version of PHP CLI
$ sudo phpenmod -s cli -v 7.4 swoole
# Check if the Swoole extension has been enabled
$ php -m | grep swoole
You can also disable Swoole using
if you need to (this is not uninstalling, just turning Swoole off):
#!/bin/bash
# Turn off Swoole for CLI or a specific PHP install
sudo phpdismod -s cli swoole
sudo phpdismod -s cli -v 7.4 swoole
2021年6月23日 laravel
laravel-echo-server启动需要比较长时间,如果通过supervisor来监控laravel-echo-server的运行状态,极有可能在默认情况下超时导致重新启动,很容易就死循环了。
startsecs默认是10,如果进程启动有可能超过10秒,则设置大一点吧
;[program:example]
;command=/bin/echo; the program (relative uses PATH, can take args)
;priority=999 ; the relative start priority (default 999)
;autostart=true ; start at supervisord start (default: true)
;autorestart=true ; retstart at unexpected quit (default: true)
;startsecs=10 ; number of secs prog must stay running (def. 10)
;startretries=3 ; max # of serial start failures (default 3)
;exitcodes=0,2 ; 'expected' exit codes for process (default 0,2)
;stopsignal=QUIT ; signal used to kill process (default TERM)
;stopwaitsecs=10 ; max num secs to wait before SIGKILL (default 10)
;user=chrism ; setuid to this UNIX account to run the program
;log_stdout=true ; if true, log program stdout (default true)
;log_stderr=true ; if true, log program stderr (def false)
;logfile=/var/log/supervisor.log ; child log path, use NONE for none; default AUTO
;logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
;logfile_backups=10 ; # of logfile backups (default 10)
;command=/bin/echo; supervisor启动时将要开启的进程。相对或绝对路径均可。若是相对路径则会从supervisord的$PATH变中查找。命令可带参数。
;priority=999 指明进程启动和关闭的顺序。低优先级表明进程启动时较先启动关闭时较后关闭。高优先级表明进程启动时启动时较后启动关闭时较先关闭。
;autostart=true 是否随supervisord启动而启动
;autorestart=true 进程意外退出后是否自动重启
;startsecs=10 进程持续运行多久才认为是启动成功
;startretries=3 重启失败的连续重试次数
;exitcodes=0,2 若autostart设置为unexpected且监控的进程并非因为supervisord停止而退出,那么如果进程的退出码不在exitcode列表中supervisord将重启进程
;stopsignal=QUIT 杀进程的信号
;stopwaitsecs=10 向进程发出stopsignal后等待OS向supervisord返回SIGCHILD 的时间。若超时则supervisord将使用SIGKILL杀进程