0

I am not sure on any of the technical terms, but I think I am describing this in an understandable way.

I am going to write a php script which will listen on a port, and send out data as necessary, i.e. a basic game listening process. There are many places on the web with hints about this, so I think I will be alright there, but any further suggestions on tutorials are welcome.

That is not my question. This is:

What I want to do is have a server where this script is NOT automatically running. What I want instead is when someone fires up the game on their client, it will do a test to see if there is a listening script running already on my server, and if not it will launch it. (I am not sure how to do that yet, but I don't expect that to be too hard. Just send some data to that port and see if there is a response.)

Then when other people join, they will see the script running on the server and use that rather than launching their own.

Are there problems with this idea?

If the first person quits, will the script close down?

Would it be better to let the 'first player' launch the script and put a requirement on the script that it does not shut down. (I.e. the script will run forever until the server gets a restart - basically my server does not mind me running long running scripts, as long as they don't use too much processing, but they don’t allow me to have scripts to start-up if the server is relaunched.)

Would this run-forever script avoid any 'first-player' shutdown problem?

If two people are deemed the 'first player' when they do a check to see if the script is running, but then one of those people launch the script milliseconds before the other, surely this will create two scripts on the server, causing a kind of echo effect for listening. How would I overcome this?

Jon

Rewind
  • 2,554
  • 3
  • 30
  • 56
  • 1
    Sorry but "listening on a port" == "script running". Yes, you could run a script forever if you have the privileges to do so (take a look at `max_execution_time`). – HamZa Mar 29 '13 at 15:01
  • Thanks HamZa for your reply. I will look into my server's max_execution_time value. Will the 'first-player' turning off their window shut down the script execution? Also, can I change the max_execution_time in my php script? – Rewind Mar 29 '13 at 15:59
  • It depends all on what you put in your code, this is too broad to just explain. But yes you could do that if you want to. – HamZa Mar 29 '13 at 16:04
  • You can change max_execution_time in your script by using `ini_set('max_execution_time', 300);` Where 300 is x seconds (that's 5mn).... – HamZa Mar 29 '13 at 16:05
  • ini_set looks nice, as it appears to only temporarily reset the value just for that script. If I changed the 300 to 0 would that mean indefinitely? – Rewind Mar 29 '13 at 16:37
  • That would mean that your script will run forever, but you should check [this question/answer](http://stackoverflow.com/questions/4306605/is-ini-setmax-execution-time-0-a-bad-idea) as there may be other factors ... – HamZa Mar 29 '13 at 18:56

0 Answers0