8000 Add "executable" option to server:run console command by tomasfejfar · Pull Request #23721 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Add "executable" option to server:run console command #23721

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move executable finding fallback to WebServerConfig
  • Loading branch information
tomasfejfar committed Nov 3, 2017
commit 2feb0642c31a73203df67810eb6ff83c344e1f7b
8 changes: 0 additions & 8 deletions src/Symfony/Bundle/WebServerBundle/WebServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Symfony\Bundle\WebServerBundle;

use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\RuntimeException;

Expand Down Expand Up @@ -147,13 +146,6 @@ private function createServerProcess(WebServerConfig $config)
{
$executable = $config->getExecutable();

if ($executable === null) {
$finder = new PhpExecutableFinder();
if (false === $executable = $finder->find()) {
throw new \RuntimeException('Unable to find the PHP executable.');
}
}

$process = new Process(array($executable, '-S', $config->getAddress(), $config->getRouter()));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we should "explode" $executable string. Depending on how the Process class is escaping the array, the first one will be the command name, see the example:

$ 'echo -e test'
bash: echo -e test: command not found

If you pass a whole string as the command, it will be interpreted as its name. I did not test it, but I believe it will do the same in the end.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, yes... definitely. Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not as simple as it seems. Consider following executable: php -dmemory_limit=16M -dzend_extension="C:\Program Files\some_extension.dll". If I were to split this with spaces, it would break around the Program Files part. And parsing CLI arguments is way over the scope of this PR IMHO. I've googled for some ready-made solutions and everything is in the ballpark of hundred lines of code.

I tried to repurpose \Symfony\Component\Console\Input\StringInput for this, but it feels very hacky and I needed to add new public method to it.

See 50fda23

Tested with php index.php s:r --docroot web\ --executable "php -dmemory_limit=512M -dinclude_path=\"c:\Program Files\""

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any suggestions welcome

$process->setWorkingDirectory($config->getDocumentRoot());
$process->setTimeout(null);
Expand Down
9 changes: 9 additions & 0 deletions src/Symfony/Bundle/WebServerBundle/WebServerConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Symfony\Bundle\WebServerBundle;

use Symfony\Component\Process\PhpExecutableFinder;

/**
* @author Fabien Potencier <fabien@symfony.com>
*/
Expand Down Expand Up @@ -71,6 +73,13 @@ public function __construct($documentRoot, $env, $address = null, $router = null
throw new \InvalidArgumentException(sprintf('Port "%s" is not valid.', $this->port));
}

if ($executable === null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yoda-style as well

$finder = new PhpExecutableFinder();
if (false === $executable = $finder->find()) {
throw new \RuntimeException('Unable to find the PHP executable.');
}
}

$this->executable = $executable;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I welcome any suggestions on how to validate this. Using is_executable would only work for full paths. And this can be anything from xdebug (from my original issue) to /usr/bin/php7_custom_build -c /custom/php.ini.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now the command would just fail on the higher layer (in WebServer::run)

}

Expand Down
0