PHP code example of w7 / rangine-http-message

1. Go to this page and download the library: Download w7/rangine-http-message library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

w7 / rangine-http-message example snippets


$server = new \Swoole\Http\Server('0.0.0.0', 88, SWOOLE_PROCESS, SWOOLE_SOCK_TCP);

$server->on('request', function ($request, $response) {
	$psr7Request = \W7\Http\Message\Server\Request::loadFromSwooleRequest($request);
	$psr7Response = new \W7\Http\Message\Server\Response();
	$psr7Response->setOutputer(new \W7\Http\Message\Outputer\SwooleResponseOutputer($response));
	
	//获取 Post 
	$code = $psr7Request->post('code');

	// 发送一个文件
	// $filePath 下载的文件物理路径
	// $startPos 需要分片下载时,指定文件的开始位置 
	// $chunkFileSize 需要分片下载时,每个分片的大小
	$psr7Response->withFile(new File($filePath, $startPos, $chunkFileSize));
});

$server->start();

$psr7Request = \W7\Http\Message\Server\Request::loadFromFpmRequest();
$psr7Response = new \W7\Http\Message\Server\Response();
$psr7Response->setOutputer(new \W7\Http\Message\Outputer\FpmResponseOutputer());