Aparece o seguinte erro qdo executo:
[root@OMEGA bin]# bash /var/www/html/josy/socket/server
: Arquivo ou diretório não encontradoe 2: ?php
: command not foundsocket/server: line 3:
/var/www/html/josy/socket/server: line 4: syntax error near unexpected token `'MAXLINE','
'var/www/html/josy/socket/server: line 4: ` define('MAXLINE', 1024); //TAMANHO DO SOCKET RECEBIDO
Não sei se por falta de permissão ou se a primeira linha do meu script tem q buscar onde esta o php no meu servidor?
Se alguem souber me dar uma dica, ja agradeço
#!/usr/local/bin/php -q
<?php
define('MAXLINE', 1024); //TAMANHO DO SOCKET RECEBIDO
define('LISTENQ', 5);
define('PORT', 81); //PORTA PADRÃO PARA CONEXÃO
define('FD_SETSIZE', 2); //Nº MÁXIMO DE CLIENTES PERMITIDO POR CONEXÃO
//PARA MATAR O SERVIDOR
function killDaemon()
{
global $listenfd, $client;
$msg = "Fechando servidor!!\n";
for ($i = 0; $i < FD_SETSIZE; $i++)
{
if ($client[$i] != null)
{
socket_write($client[$i], $msg, strlen($msg));
socket_close($client[$i]);
}
}
print "DESCONECTAR!!\n";
socket_close($listenfd);
exit;
}
//QUANDO O CLIENTE DESCONECTAR
function closeClient($i)
{
global $client, $remote_host, $remote_port;
print "closing client[$i] ({$remote_host[$i]}:{$remote_port[$i]})\n";
socket_close($client[$i]);
$client[$i] = null;
unset($remote_host[$i]);
//VERIFICA SE HÁ CLIENTE CONECTADO, FAZ O DESCONECT
$someoneconnected = false;
for ($i = 0; $i <= FD_SETSIZE; $i++){
if($client[$i] != null)
{
$someoneconnected = true;
break;
}
}
if($someoneconnected == false)
{
killDaemon();
}
}
$listenfd = socket_create(AF_INET, SOCK_STREAM, 0);
if ($listenfd)
print "Escutando a porta " . PORT . "\n";
else
die("Socket morreu!!\n");
//CONFIGURAÇÃO IP DO SERVER
socket_setopt($listenfd, SOL_SOCKET, SO_REUSEADDR, 0);
if (!socket_bind($listenfd, "0.0.0.0", PORT))
{
socket_close($listenfd);
die("Não foi possível conectar!!\n");
}
socket_listen($listenfd, LISTENQ);
for ($i = 0; $i < LISTENQ; $i++)
$client[$i] = null;
while(1)
{
$rfds[0] = $listenfd;
{
for ($i = 0; $i <= FD_SETSIZE; $i++)
if ($client[$i] != null)
$rfds[$i + 1] = $client[$i];
}
//BLOQUEIA INDEFINITAMENTE ATÉ RECEBER UMA CONEXÃO
$nready = socket_select($rfds, $null, $null, null);
//SE TEMOS UMA CONEXÃO
if (in_array($listenfd, $rfds))
{
print "Listenfd ouviu algo, criando novo cliente!!\n";
//PEGA O NOVO LOCAL
for ($i = 0; $i <= FD_SETSIZE; $i++)
{
if ($client[$i] == null)
{
$client[$i] = socket_accept($listenfd);
socket_setopt($client[$i], SOL_SOCKET, SO_REUSEADDR, 0);
socket_getpeername($client[$i], $remote_host[$i], $remote_port[$i]);
print "Aceitar {$remote_host[$i]}:{$remote_port[$i]} as client[$i]\n";
if ($i < FD_SETSIZE)
{
break;
}
}
if ($i >= FD_SETSIZE)
{
//NO CASO DE MUITOS CLIENTES
closeClient($i);
break;
}
}
if (--$nready <= 0)
continue;
}
//VERIFICA OS CLIENTES PARA RECEPÇÃO DE DADOS
for ($i = 0; $i <= FD_SETSIZE; $i++)
{
if ($client[$i] == null)
continue;
if (in_array($client[$i], $rfds))
{
$n = trim(socket_read($client[$i], MAXLINE));
if (!$n)
closeClient($i);
else
{
//QDO O CLIENTE ENVIA OS DADOS ABAIXO
if ($n == "/killme")
killDaemon();
else if ($n == "/quit")
closeClient($i);
else
{
//IMPRIME ALGO NO SERVIDOR
print "From {$remote_host[$i]}:{$remote_port[$i]},>client[$ i]: $n\n";
for ($j = 0; $j <= FD_SETSIZE; $j++)
{
if ($client[$j] != null)
socket_write($client[$j], "From client[$i]: $n".chr(0));
}
}
}
if (--$nready <= 0)
break;
}
}
}
?>










