Skip to content

Instantly share code, notes, and snippets.

@ninjapanzer
Created October 25, 2016 21:07
Show Gist options
  • Select an option

  • Save ninjapanzer/fc33cefe6842a70f85cea62ee8d67693 to your computer and use it in GitHub Desktop.

Select an option

Save ninjapanzer/fc33cefe6842a70f85cea62ee8d67693 to your computer and use it in GitHub Desktop.
Lumen Artisan Serve Command
<?php
namespace App\Console\Commands;
use Exception;
use Illuminate\Console\Command;
use Symfony\Component\Process\ProcessUtils;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Process\PhpExecutableFinder;
class ServeCommand extends Command
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'serve';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Serve the application on the PHP development server';
/**
* Execute the console command.
*
* @return void
*
* @throws \Exception
*/
public function fire()
{
chdir($this->laravel->basePath()."/public");
$host = $this->input->getOption('host');
$port = $this->input->getOption('port');
$base = ProcessUtils::escapeArgument($this->laravel->basePath()."/public");
$binary = ProcessUtils::escapeArgument((new PhpExecutableFinder)->find(false));
$this->info("Lumen development server started on http://{$host}:{$port}/");
if (defined('HHVM_VERSION')) {
if (version_compare(HHVM_VERSION, '3.8.0') >= 0) {
passthru("{$binary} -m server -v Server.Type=proxygen -v Server.SourceRoot={$base}/ -v Server.IP={$host} -v Server.Port={$port} -v Server.DefaultDocument=server.php -v Server.ErrorDocument404=index.php");
} else {
throw new Exception("HHVM's built-in server requires HHVM >= 3.8.0.");
}
} else {
passthru("{$binary} -S {$host}:{$port} {$base}/index.php");
}
}
/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return [
['host', null, InputOption::VALUE_OPTIONAL, 'The host address to serve the application on.', 'localhost'],
['port', null, InputOption::VALUE_OPTIONAL, 'The port to serve the application on.', 8000],
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment