承接 thenlabs/http-server 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

thenlabs/http-server

Composer 安装命令:

composer require thenlabs/http-server

包简介

README 文档

README

A HTTP server written in PHP with help of the Symfony Components.

If you like this project gift us a ⭐.

Installation.

$ composer require thenlabs/http-server

Usage.

Create a file with the next example content:

You should change the content according to your needs.

<?php
// run-server.php

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

use ThenLabs\HttpServer\HttpServer;

$config = [
    'host' => '127.0.0.1',
    'port' => 8080,
    'document_root' => __DIR__.'/vendor/thenlabs/http-server/tests/Functional/document_root',
];

$server = new HttpServer($config);
$server->start();

while (true) {
    $server->run();
}

This file should be executed like that:

$ php run-server.php

Once does it, we can navigate to the URL and we will see the respectively page.

In our example, we are serving the index.html file which is stored within the tests/document_root directory.

Creating custom routes.

The HttpServer use the Symfony Routing Component for handle the routing, therefore, you can use all the his possibilities.

The next example shown the way to creating a custom route which only can be access by a GET request.

<?php

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

// ...

$server->get('/article/{id}', function (Request $request, array $parameters): Response {
    return new Response("This is the article {$parameters['id']}");
});

// ...

Using the logs.

Like you can will verify, by default are will shows in the console the result of all server requests.

The logs are created with help of the popular Monolog library.

The next example showns a way to put the logs in a file.

<?php

// ...
use Monolog\Handler\StreamHandler;

// ...
$server->getLogger()->pushHandler(new StreamHandler('/path/to/file.logs'));

Development.

Running the tests.

Start the selenium server.

$ java -jar path/to/selenium-server-standalone-x.y.z.jar

Run PHPUnit.

$ ./vendor/bin/pyramidal

统计信息

  • 总下载量: 35
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-10-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固