LoginSignup
43
35

More than 5 years have passed since last update.

俺は!!!PHPのビルトインサーバをマルチプロセスにしたいしHTTPSで使いたいぞ!!!

Last updated at Posted at 2016-08-06

動機

Guzzleの行き過ぎた抽象化があまり好みではないので,cURLとジェネレータでシンプルに気持ちよく非同期HTTPリクエストが書ける mpyw/co を書いた

それをベースに FriendsOfPHP/Goutte そっくりのインタフェースを備えた,非同期スクレイピングクライアント mpyw/coutte を書いてみた

Coutteのテスト書きたいけど,SymfonyのBrowserKitのソースコード読んでも@param arrayとか雑な型説明しか無くて,どんな構造があり得るのかわかりにくかった

実際にサーバ立ててテストしたいけど,普通のビルトインサーバだと同時リクエストさばけないしHTTPSの場合のテストができない

これだけのためにApacheとかNginxに依存したくない,composer.jsonに書いておけばそれだけで解決する世界を手に入れたい

php-cli上にビルトインサーバへのリバースプロキシ立てればいいじゃないか! (何故そうなった)

mpyw/php-hyper-builtin-server

使い方

dev-master ではツールっぽく仕上げました.ReactのSocketコンポーネントに関して,本家にPRが採用され次第,Stable出そうかと思います.

Usage:
    vendor/bin/hyper-run <options>

[Required]
    -S   Server URL such as "127.0.0.1:8080" or "https://127.0.0.1:8081".
         When protocol is omitted, it is assumed as "http://".
         When port is omitted, it is assumed as 80(http) or 443(https).
         Multiple arguments can be accepted.
         At least 1 server must be specified.
    -s   The same as -S but the default protocol is "https://".

[Optional]
    -n   The number of PHP built-in server clusters. Default is 10.
    -t   Path for document root. Default is the current directory.
    -r   Path for router script. Default is empty.
    -c   Path for alternative PEM-encoded certificate.
         Default is "....../certificate.pem".

[Restriction]
    - "https://" is supported only on PHP 5.6.0 or later.
    - Access logs are not displayed in Windows.
vendor/bin/hyper-run -S localhost:8080 -s localhost:8081 -t src/app/www

フォークするプロセスの数が前より圧倒的に少なくなっているので,コンピュータにも優しいです.

スクリーンショット 2016-08-31 17.15.15.png

スクリーンショット 2016-08-31 17.17.21.png

43
35
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
43
35