Score
0
Watch 4 Star 14 Fork 2

naka507 / phpsocketPHPMIT

Join us
Explore and code with more than 2 million developers,Free private repositories !:)
Sign up
基于Workerman 改写的简化版。 用于开发基于 Socket 的 HTTP Server 。 spread retract

Clone or download
naka507 authored ssl
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

PHPSocket

基于Workerman 改写的简化版。 用于开发基于 Socket 的 HTTP Server

安装

composer require naka1205/phpsocket

使用

http server

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

use Naka507\Socket\Server;
$server = new Server();

//服务启动
$server->onWorkerStart = function($worker)
{
    echo "New onWorkerStart\n";
};

//建立连接
$server->onConnect = function($connection)
{
    echo "New Connection\n";
};

//接收请求
$server->onMessage = function($request, $response)
{
    $response->write(' Hello World !!!');
    $response->end();
};
$server->start();

https server

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

use Naka507\Socket\Server;
$opt = array(
    'ssl' => array(
        // 请使用绝对路径
        'local_cert'                 => '/***/fullchain.pem',
        'local_pk'                   => '/***/privkey.pem',
        'verify_peer'                => false,
        'allow_self_signed' 		 => true 
    )
);
$server = new Server(443,$opt);
$server->transport = 'ssl';

//服务启动
$server->onWorkerStart = function($worker)
{
    echo "New onWorkerStart\n";
};

//建立连接
$server->onConnect = function($connection)
{
    echo "New Connection\n";
};

//接受请求
$server->onMessage = function($request, $response)
{
    $response->write(' SSL: Hello World !!!');
    $response->end();
};
$server->start();

WINDOWS

php app.php

LINUX

DEBUG 模式 (默认)

php app.php

守护进程

php app.php -d

关闭进程

php app.php -s

浏览器访问

http://127.0.0.1:8000 https://域名。

Comments ( 2 )

Sign in for post a comment

PHP
1
https://gitee.com/naka507/phpsocket.git
git@gitee.com:naka507/phpsocket.git
naka507
phpsocket
phpsocket
master

Help Search