socket.io-php:install.json中的“缺少脚本:开始”

时间:2020-04-01 14:22:18

标签: javascript php node.js socket.io

我想创建一个支持某些PHP API的.io游戏,并尝试执行以下文件:

install.json:

{
    "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"}
    }
}

start.php

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

如何解决此错误并成功执行此程序包?

1 个答案:

答案 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"}
    }
}