Jump to content

Running PHP file as a services


Recommended Posts

Well, it started when I've developed a socket server using PHP. Currently I use the command line below to start the server:

php -q Server.php

 

So I want it to be installed on the server as a service. So I can do something like this:

service MyPHPServer start [Linux]
sc start MyPHPServer [windows]

 

So far I've got this which is using cmd to launch a batch file and the batch file will start the server:

C:\Windows\System32\cmd.exe /c C:\my_service_path\startup.bat (I've tried only in Windows)

 

Then I put this line in my batch file (assumed the php file is located same directory as the batch file):

php -q Server.php

 

It was added to the service registry. But when I tried to start it, i got a message:

[sC] StartService FAILED 1053:

The service did not respond to the start or control request in a timely fashion.

 

I know this is not the way, just wonder anyone tried to start a PHP file as a service before and share their experience.  ;)

Link to comment
https://forums.phpfreaks.com/topic/209306-running-php-file-as-a-services/
Share on other sites

To be honest, I'm not sure what signals I'm suggesting be implemented either.  I'm quite curious on this now, so I might try to make a PHP-script as a service later.  I didn't know that script-level PHP could accept signals.  I guess I should have expected that :).  (To think, I doubted PHP!)

 

Now, I'm not sure as to what the signals exactly are, since in C++ using managed code in Visual Studio, the code of a service extends System::ServiceProcess::ServiceBase and implements OnStart and OnStop (there's also OnPause I think, but that's optional).

 

So it could actually be based on exports or something, but I would say 99.99999% chance it's based on signals, and that somewhere in the ServiceBase code it handles all that (except of course, that code isn't accessible, just the headers ;p).

 

 

 

If I get anything working later, I'll post it.

Well you would have to know what signals Windows sends the program.  I more I think about it though, the more I'm not entirely sure if it is 100% signal based.  Haven't gotten around to trying it myself yet though.

 

 

Ahh, just googled, and it looks like Windows does not have signals in the sense that Unix does.... http://stackoverflow.com/questions/140111/sending-an-arbitrary-signal-in-windows

 

I think what I'll do is look into the Apache source to see how it handles services as I don't even know how to get started with service stuff without using managed code.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.