Giter Club home page Giter Club logo

m2php's Introduction

m2php - a library to develop Mongrel2 handlers in PHP

Requirements

Fetch

The recommended way to install m2php is through composer.

Just create a composer.json file for your project:

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

And run these two commands to install it:

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

Now you can add the autoloader, and you will have access to the library:

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

Usage

<?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');
}

Example

Before running the example, you need to have composer set up an autoloader:

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

Now you can run the example.

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

Tests

Before running the tests you need to have composer set up an autoloader:

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

Now you can run the unit tests.

$ phpunit

LICENSE

New BSD, see LICENSE.

m2php's People

Contributors

igorw avatar javiern avatar winks avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

m2php's Issues

hhvm compatibility

What do you think of using hhvm with m2php and Mongrel2. The PHP would also need some sort of async framework like React.

Does not populate standard PHP-expected server API variables

I haven't tried the code yet but I've reviewed every line and it seems that it doesn't set up any of the standard webserver variables such as _GET or _POST or _SERVER. Almost every single PHP application expects these so-called "superglobals" to exist.

This code doesn't looks to have been touched since last summer - is there any progress being made here?

Unable To Send Multiple of the Same Header Type

Tool.php (see following code block or line 25-29) incorrectly assumes that only one of a certain header type will be sent per response. This is mostly true, except in the case of cookies. Cookies use the Set-Cookie header. eg, "Set-Cookie: name=value; Expires=Wed, 01-Apr-2021 00:00:00 GMT".

$headers['Content-Length'] = strlen($body);
$hd = "";
foreach($headers as $k => $v) {
    $hd .= sprintf("%s: %s\r\n", $k, $v);
}

However, setting multiple cookies within one request using the current $headers scheme ($headers[$header_name] = $header_value) will not work.

I suggest revising this so that $headers is no longer an associative array, and is instead just an array of strings. These strings will be the fully-written header, identical to the argument one would pass to the header() function, eg, "Set-Cookie: name=value".

As a temporary workaround for those that run into this issue,

$headers['Set-Cookie'] = "name=value;\r\nSet-Cookie: name2=value";

http://en.wikipedia.org/wiki/HTTP_cookie#Setting_a_cookie
http://php.net/manual/en/function.header.php

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.