自動加載
如果你的項(xiàng)目沒有實(shí)現(xiàn)自動加載,可以利用composer生成一個,步驟如下。
1. 更改composer.json
在composer.json里autoload.psr-4 加入 "" : "./"
,例如
{
"require": {
"workerman/workerman" : "^v4.0.0"
},
"autoload": {
"psr-4": {
"" : "./"
}
}
}
2. 生成autoload.php
執(zhí)行 composer dumpautoload
3. 加載autoload.php
在項(xiàng)目start.php頭部加載vendor/autoload.php
例如
<?php
require_once __DIR__ . '/vendor/autoload.php';
4. 重啟workerman
php start.php restart