File tree Expand file tree Collapse file tree 3 files changed +30
-2
lines changed
Expand file tree Collapse file tree 3 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ A small library to help run PHP servers easily and quickly.
55## Installation
66
77```
8- composer require ahmard/php-server
8+ composer require ahmard/php-server --dev
99```
1010
1111## Usage
@@ -55,3 +55,17 @@ Server::create('127.0.0.1', '9900')
5555 ->onRequest(fn() => var_dump('Request Received'))
5656 ->start();
5757```
58+
59+ - Use preferred php version/executable
60+
61+ ``` php
62+ use PHPServer\BuiltIn\Server;
63+
64+ Server::create('127.0.0.1', '9900')
65+ ->setWorkers(2)
66+ ->setPHPExecutable('/usr/bin/php8.0')
67+ ->onRequest(fn() => var_dump('Request Received'))
68+ ->start();
69+ ```
70+
71+ Enjoy 😎
Original file line number Diff line number Diff line change @@ -12,14 +12,15 @@ class Server extends AbstractServer
1212{
1313 protected string |null $ documentRoot = null ;
1414 protected string |null $ routerScript = null ;
15+ protected string $ PHPExecutable = 'php ' ;
1516 protected Closure |null $ requestCallback = null ;
1617 protected int |null $ workers = null ;
1718
1819
1920 public function getCommand (): ServerCommand
2021 {
2122 $ config = $ this ->getInfo ();
22- $ command = "php -S {$ config ->getHost ()}: {$ config ->getPort ()}" ;
23+ $ command = "$ this -> PHPExecutable -S {$ config ->getHost ()}: {$ config ->getPort ()}" ;
2324
2425 if (null != $ this ->workers ) {
2526 $ command = "PHP_CLI_SERVER_WORKERS= $ this ->workers $ command " ;
@@ -68,4 +69,16 @@ public function setWorkers(int $num): static
6869 $ this ->workers = $ num ;
6970 return $ this ;
7071 }
72+
73+ /**
74+ * Use custom/preferred php version/executable
75+ *
76+ * @param string $path
77+ * @return $this
78+ */
79+ public function setPHPExecutable (string $ path ): static
80+ {
81+ $ this ->PHPExecutable = $ path ;
82+ return $ this ;
83+ }
7184}
Original file line number Diff line number Diff line change 77Server::create ('0.0.0.0 ' , 9904 )
88 ->onRequest (fn () => var_dump ('Request Received ' ))
99 ->setWorkers (3 )
10+ ->setPHPExecutable ('/usr/bin/php8.0 ' )
1011 ->start ()
1112 ->logOutputToConsole ();
You can’t perform that action at this time.
0 commit comments