File tree 3 files changed +30
-2
lines changed
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.
5
5
## Installation
6
6
7
7
```
8
- composer require ahmard/php-server
8
+ composer require ahmard/php-server --dev
9
9
```
10
10
11
11
## Usage
@@ -55,3 +55,17 @@ Server::create('127.0.0.1', '9900')
55
55
->onRequest(fn() => var_dump('Request Received'))
56
56
->start();
57
57
```
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
12
12
{
13
13
protected string |null $ documentRoot = null ;
14
14
protected string |null $ routerScript = null ;
15
+ protected string $ PHPExecutable = 'php ' ;
15
16
protected Closure |null $ requestCallback = null ;
16
17
protected int |null $ workers = null ;
17
18
18
19
19
20
public function getCommand (): ServerCommand
20
21
{
21
22
$ config = $ this ->getInfo ();
22
- $ command = "php -S {$ config ->getHost ()}: {$ config ->getPort ()}" ;
23
+ $ command = "$ this -> PHPExecutable -S {$ config ->getHost ()}: {$ config ->getPort ()}" ;
23
24
24
25
if (null != $ this ->workers ) {
25
26
$ command = "PHP_CLI_SERVER_WORKERS= $ this ->workers $ command " ;
@@ -68,4 +69,16 @@ public function setWorkers(int $num): static
68
69
$ this ->workers = $ num ;
69
70
return $ this ;
70
71
}
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
+ }
71
84
}
Original file line number Diff line number Diff line change 7
7
Server::create ('0.0.0.0 ' , 9904 )
8
8
->onRequest (fn () => var_dump ('Request Received ' ))
9
9
->setWorkers (3 )
10
+ ->setPHPExecutable ('/usr/bin/php8.0 ' )
10
11
->start ()
11
12
->logOutputToConsole ();
You can’t perform that action at this time.
0 commit comments