我想创建一个支持某些PHP API的.io游戏,并尝试执行以下文件:
{
"name" : "workerman/phpsocket.io",
"type" : "library",
"keywords": ["socket.io"],
"homepage": "http://www.workerman.net",
"license" : "MIT",
"require": {
"workerman/workerman" : ">=3.5.16",
"workerman/channel" : ">=1.0.0"
},
"autoload": {
"psr-4": {"PHPSocketIO\\": "./src"}
}
}
use Workerman\Worker;
use PHPSocketIO\SocketIO;
require_once __DIR__ . '/vendor/autoload.php';
// Listen port 2021 for socket.io client
$io = new SocketIO(2021);
$io->on('connection', function ($socket) use ($io) {
$socket->on('chat message', function ($msg) use ($io) {
$io->emit('chat message', $msg);
});
});
Worker::runAll();
它在执行命令npm start
时给了我这个错误:
npm ERR! missing script: start
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\usuario\AppData\Roaming\npm-cache\_logs\2020-04-01T14_16_55_432Z-debug.log
如何解决此错误并成功执行此程序包?
答案 0 :(得分:0)
您可能必须提供要运行的脚本。就您而言,install.js
?
{
"name" : "workerman/phpsocket.io",
"type" : "library",
"keywords": ["socket.io"],
"homepage": "http://www.workerman.net",
"license" : "MIT",
"scripts": {
"start": "npm run install.js"
},
"require": {
"workerman/workerman" : ">=3.5.16",
"workerman/channel" : ">=1.0.0"
},
"autoload": {
"psr-4": {"PHPSocketIO\\": "./src"}
}
}