0

i have a code for Client and Server Socket Programming.. In Server.php file, i am reading data from client and uploading same data to mysql.

$input = socket_read($spawn, 1024) or die("Could not read input\n");
$sql= "INSERT into data VALUES ('$input')";

the server this code is only running whenever call that URL in browser. i need to run the server program continuously 24x7. What should i do in this particular case. Some offering hosting along with Sockets. In this case do i not need to run the server.php in browser? or is there any other way?

fvu
  • 32,488
  • 6
  • 61
  • 79
RJ501
  • 167
  • 1
  • 2
  • 10
  • 1
    Note that even if the socket isn't receiving user input, this is still vulnerable to SQL injection, or at least to bad input breaking the SQL syntax. Please be sure to escape `$input` properly. – Michael Berkowski Jul 15 '13 at 12:16

1 Answers1

0

you can simply use a while true loop but be sure to use blocking mode for the socket (socket_set_block()) or at least a sleep() inside the loop to not penetrate the server too much ;)

then there are many options to run the script on a server like in a screen session, as backgrounded process or use a tool like start-stop-deamon etc...

of course you need to regularly check if everything is up ie. using cron and restart the process if required etc...

Andreas Linden
  • 12,489
  • 7
  • 51
  • 67