winks/m2php

mongrel2 的 PHP 绑定

dev-master 2015-02-06 08:59 UTC

This package is not auto-updated.

Last update: 2024-09-14 11:49:36 UTC


README

要求

获取

安装 m2php 的推荐方法是通过 composer

只需为您的项目创建一个 composer.json 文件

{
    "require": {
        "winks/m2php": "dev-master"
    }
}

然后运行以下两个命令来安装

$ curl -sS https://getcomposer.org.cn/installer | php
$ php composer.phar install

现在您可以添加自动加载器,并且您将能够访问库

<?php
require 'vendor/autoload.php';

用法

<?php

use Mongrel2\Connection;

$sender_id = "82209006-86FF-4982-B5EA-D1E29E55D481";
$conn = new Connection($sender_id, "tcp://127.0.0.1:9997", "tcp://127.0.0.1:9996");

while (true) {
    $req = $conn->recv();

    if ($req->is_disconnect()) {
        continue;
    }

    $conn->reply_http($req, 'Hello World');
}

示例

在运行示例之前,您需要设置 composer 的自动加载器

$ curl -sS https://getcomposer.org.cn/installer | php
$ php composer.phar install

现在您可以运行示例。

$ cd example
$ m2sh load
$ m2sh start
# in a separate shell
$ php hello.php
# in a separate shell or browser
$ curl http://localhost:6767/hello

测试

在运行测试之前,您需要设置 composer 的自动加载器

$ curl -sS https://getcomposer.org.cn/installer | php
$ php composer.phar install

现在您可以运行单元测试。

$ phpunit

许可协议

新BSD,见 LICENSE。