-
-
Save barryvdh/75667b91f4cd9820ae9c746d752166b7 to your computer and use it in GitHub Desktop.
Example scenarios
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"require": { | |
"hollodotme/fast-cgi-client": "^2.0", | |
"symfony/process": "^4.2" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Bootstrap | |
require 'vendor/autoload.php'; | |
use hollodotme\FastCGI\Client; | |
use hollodotme\FastCGI\Requests\GetRequest; | |
use hollodotme\FastCGI\SocketConnections\UnixDomainSocket; | |
class Scenarios { | |
protected $num = 10; | |
protected $callables = ['runExec', 'runProcess', 'runFastcgi']; | |
protected $client; | |
public function __construct() | |
{ | |
$connection = new UnixDomainSocket('/Users/barry/.valet/valet.sock'); | |
$this->client = new Client( $connection ); | |
} | |
public function runAll() { | |
foreach ($this->callables as $callable) { | |
// Cold start | |
$start = microtime(true); | |
$output = call_user_func([$this, $callable]); | |
// echo $output; | |
echo("$callable COLD: " . round((microtime(true) - $start) * 1000, 2) . "ms\n"); | |
$start = microtime(true); | |
// Hot start | |
for ($i=0; $i<$this->num; $i++) { | |
$output = call_user_func([$this, $callable]); | |
// echo $output; | |
} | |
echo("$callable HOT: " . round(((microtime(true) - $start) / $this->num) * 1000, 2) . "ms\n"); | |
} | |
} | |
public function runExec() | |
{ | |
return exec('php script.php'); | |
} | |
public function runProcess() | |
{ | |
$process = new \Symfony\Component\Process\Process(['/usr/local/bin/php', 'script.php']); | |
$process->setTimeout(null); | |
// This waits for the process to finish (i.e. waits until an event has been processed) | |
$process->run(); | |
return $process->getOutput(); | |
} | |
public function runFastcgi() | |
{ | |
$request = new GetRequest(__DIR__ .'/script.php', ''); | |
$response = $this->client->sendRequest($request); | |
return $response->getBody(); | |
} | |
} | |
$scenarios = new Scenarios(); | |
$scenarios->runAll(); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
echo microtime(true) . " - Hello world!\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment