xenophobia Posted July 30, 2010 Share Posted July 30, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/209306-running-php-file-as-a-services/ Share on other sites More sharing options...
corbin Posted August 2, 2010 Share Posted August 2, 2010 Hi... To have a program run as a Windows service, it has to have handling for certain interrupts and signals (has to implement a certain set of code). Basically it's impossible with a PHP script without heavily modifying the PHP core. Quote Link to comment https://forums.phpfreaks.com/topic/209306-running-php-file-as-a-services/#findComment-1093959 Share on other sites More sharing options...
xenophobia Posted August 2, 2010 Author Share Posted August 2, 2010 How about PHP GTK? Quote Link to comment https://forums.phpfreaks.com/topic/209306-running-php-file-as-a-services/#findComment-1093971 Share on other sites More sharing options...
trq Posted August 2, 2010 Share Posted August 2, 2010 How about PHP GTK? Gtk is a GUI library. Quote Link to comment https://forums.phpfreaks.com/topic/209306-running-php-file-as-a-services/#findComment-1093988 Share on other sites More sharing options...
xenophobia Posted August 2, 2010 Author Share Posted August 2, 2010 :'( Thanks for the cruel answer. >< Haha... Okay, looks like I gonna write my server in other language. Quote Link to comment https://forums.phpfreaks.com/topic/209306-running-php-file-as-a-services/#findComment-1094005 Share on other sites More sharing options...
trq Posted August 2, 2010 Share Posted August 2, 2010 You can handle signals/interrupts in php's cli via pcntl_signal. I'm not much of a windows user so I'm not sure what signals corbin is suggesting you must implement, but I'm sure that would be documented somewhere. Quote Link to comment https://forums.phpfreaks.com/topic/209306-running-php-file-as-a-services/#findComment-1094008 Share on other sites More sharing options...
corbin Posted August 3, 2010 Share Posted August 3, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/209306-running-php-file-as-a-services/#findComment-1094438 Share on other sites More sharing options...
xenophobia Posted August 3, 2010 Author Share Posted August 3, 2010 ehh, i know not much about program signal. But I've tried pcntl_signal() on Windows and it was not working. Quote Link to comment https://forums.phpfreaks.com/topic/209306-running-php-file-as-a-services/#findComment-1094440 Share on other sites More sharing options...
corbin Posted August 3, 2010 Share Posted August 3, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/209306-running-php-file-as-a-services/#findComment-1094452 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.