Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #4898 > unrolled thread
| Started by | "sl@exabyte" <sb5309@hotmail.com> |
|---|---|
| First post | 2012-02-19 15:13 +0800 |
| Last post | 2012-02-19 13:26 +0100 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.php
Do I still CLI version of PHP "sl@exabyte" <sb5309@hotmail.com> - 2012-02-19 15:13 +0800
Re: Do I still CLI version of PHP "J.O. Aho" <user@example.net> - 2012-02-19 10:05 +0100
Re: Do I still CLI version of PHP "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-02-19 13:26 +0100
| From | "sl@exabyte" <sb5309@hotmail.com> |
|---|---|
| Date | 2012-02-19 15:13 +0800 |
| Subject | Do I still CLI version of PHP |
| Message-ID | <jhq7fr$8om$1@news.albasani.net> |
On my webserver:
*PHP version is 5.3.6
*server API: CGI/FastCGI
I need to run a socket server. A sample snippet is below:
#!/usr/local/bin/php -q
<?php
//file name: server_socket.php
.....
while (true) { // Loop continuously
// Setup clients listen socket for reading
$read[0] = $sock;
$ready = socket_select($read,null,null,null);
// If a client is trying to write - handle it now
for ($i = 0; $i < $max_clients; $i++) // for each client
{
if (in_array($client[$i]['sock'] , $read))
{
$input = socket_read($client[$i]['sock'] , 1024);
if ($input == null)
unset($client[$i]); // Zero length string meaning disconnected
$n = trim($input);
if ($input == 'exit') {
socket_close($client[$i]['sock']); // requested disconnect
} elseif ($input) {
// strip white spaces and write back to user
$output = ereg_replace("[ \t\n\r]","",$input).chr(0);
socket_write($client[$i]['sock'],$output);
}
} else {
socket_close($client[$i]['sock']);
unset($client[$i]);
}
}
} // end while
socket_close($sock);
?>
Questions:
1. Do still need the line '#!/usr/local/bin/php -q' is I call the file via
http, eg http://domain/server_socket.php, because the program is looping ?
2. If the answer to Q1is yes, how do I run my server program (I think the
version on my server is CGI) ?
Thanks
[toc] | [next] | [standalone]
| From | "J.O. Aho" <user@example.net> |
|---|---|
| Date | 2012-02-19 10:05 +0100 |
| Message-ID | <9qbsb8FpmvU1@mid.individual.net> |
| In reply to | #4898 |
sl@exabyte wrote: > 1. Do still need the line '#!/usr/local/bin/php -q' is I call the file via > http, eg http://domain/server_socket.php, because the program is looping ? No, as the web service will be calling the php interpreter, but as soon as you leave the "page" with your browser the script will die. > 2. If the answer to Q1is yes, how do I run my server program (I think the > version on my server is CGI) ? You need to have shell access and run the script in background or in a screen (or rewrite it so it can be run as a daemon). -- //Aho
[toc] | [prev] | [next] | [standalone]
| From | "M. Strobel" <sorry_no_mail_here@nowhere.dee> |
|---|---|
| Date | 2012-02-19 13:26 +0100 |
| Message-ID | <9qc837Fk21U1@mid.uni-berlin.de> |
| In reply to | #4898 |
Am 19.02.2012 08:13, schrieb sl@exabyte:
> On my webserver:
> *PHP version is 5.3.6
> *server API: CGI/FastCGI
>
> I need to run a socket server. A sample snippet is below:
>
> #!/usr/local/bin/php -q
>
> <?php
>
> //file name: server_socket.php
>
> .....
>
> while (true) { // Loop continuously
>
> // Setup clients listen socket for reading
>
> $read[0] = $sock;
>
---cut
>
>
> Questions:
>
> 1. Do still need the line '#!/usr/local/bin/php -q' is I call the file via
> http, eg http://domain/server_socket.php, because the program is looping ?
>
> 2. If the answer to Q1is yes, how do I run my server program (I think the
> version on my server is CGI) ?
>
> Thanks
AFAIK you would never run a service, especially not a PHP service, in the web server.
In the web server normal operation is Request -> Script start -> script output ->
script end ->end of request. Long running scripts are abuse.
Either run your script as true daemon, or use a "ad hoc daemon" solution like running
your script in "screen", or starting it with "nohup".
/Str.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web