1

PHP 5.4 has the built-in server (php -S localhost:8080). I'd like to be able to "create_server" (or similar, clearly don't know the function name) from within a PHP script (and without resolving to system, system_exec, exec, or backticks), but I don't see that in the documentation. Is this possible?

cwallenpoole
  • 79,954
  • 26
  • 128
  • 166
  • 2
    By "call this", what do you mean exactly? Start up an instance of it? Note that the built-in web server is really only designed for testing and demonstration purposes. – IMSoP Mar 04 '14 at 13:11
  • 1
    How exactly do you intend to run php script anyway, if your php server is not up and running? – dkasipovic Mar 04 '14 at 13:12
  • Perhaps you're looking for this? http://stackoverflow.com/questions/8377178/running-php-5-4-built-in-web-server-outside-localhost – Steve Mar 04 '14 at 13:12
  • 1
    I have only one question - why? (answering this question may help to understand original issue and resolve it in proper way). Or is it just curiosity? – Alma Do Mar 04 '14 at 13:27
  • @AlmaDo I'd like to be able to run the server within another process. I'd like the other process to be written in PHP. – cwallenpoole Mar 04 '14 at 15:41
  • @cwallenpoole That doesn't really explain what you're trying to do and why - what does running it "within another process" mean? Do you want to be able to control it in some way (beyond start and stop)? Specifically, why do you want to avoid using `system` etc? Without that caveat, your question is a duplicate of http://stackoverflow.com/questions/13136275/how-to-start-and-stop-php-dev-server-with-exec – IMSoP Mar 04 '14 at 16:09
  • @IMSoP 1. I am looking for a way to run the server from within a PHP process because it seems like that would open opportunities to interact with the running server without actually having to make a request. This is not uncommon in other languages. Python, for example, can create servers for relatively cheap. 2. That caveat is exactly *why* this is not a duplicate. 3. If the answer is "that's impossible", I'm OK with that. If the answer's "it's possible, but it's really hard," I'm also OK with that. But I don't see documentation on how to do it or saying it is impossible. – cwallenpoole Mar 05 '14 at 10:36
  • @IMSoP Also, saying "without using `system` (etc.) makes it just like [question here]" is like saying "Sure, you could use `glob`, but I don't see how that is different from `system("ls -l");`" – cwallenpoole Mar 05 '14 at 10:39
  • @cwallenpoole Fair enough, I see where you're coming from; as far as I know, the answer is that such functionality doesn't exist. The server is a simple CLI tool for testing, and not a fully-integrated feature of the runtime, so I don't think anyone's made any "control" functions for it at all, it just runs with a particular configuration until you kill it. – IMSoP Mar 05 '14 at 11:06
  • @IMSoP That's a shame. – cwallenpoole Mar 05 '14 at 14:35

1 Answers1

1

Barring an actual trip through PHP's C source, the answer to this question seems to be "There is no way to accomplish this"

cwallenpoole
  • 79,954
  • 26
  • 128
  • 166