Newsgroup: it.comp.www.php
Titolo: problema socket, telnet...

ho un sito che, seguento determinati link, deve stabilire connessioni via
telnet su altre macchine (Unix) ed eseguire comandi, output ecc. 
finora ho utilizzato, tramite php, exec di script perl che, utilizzando
il mod_telnet di perl, fungevano da "telnet" con comandi come: 
use Net::Telnet;
$server=@ARGV[0];
$osuser=@ARGV[1];
$ospwd=@ARGV[2];
$t = new Net::Telnet ( );
$ret= $t->open($server);
$t->waitfor('/login:/');
$t->print($osuser);
$t->waitfor('/Password:/');
$t->print($ospwd);
$t->waitfor("/> /");
$comando = "comando unix";
@lines = $t->cmd(String => $comando, Timeout => 270, Prompt => "/> /");
print @lines;
@trash= $t->cmd("logout");
e l'output veniva catturato da php che lo visualizzava.
questo perché PHP, già compilato per windows, non mi supportava
l'apertura di socket. 
adesso, dopo dure battaglie, sono riuscito a migrare su Linux il mio
webserver ed ho ricompilato il php in modo da avere i socket abilitati. 
mi piacerebbe tradurre in PHP i miei scripts ma mi sembra che utilizzare
il TELNET con socket(), connect(), read() e write() sia un po' duro. non
sapete se c'è qualche modulo con qualche funzione già scritta come per
mod_telnet di perl?? 
o qualche script di esempio che utilizzi le funzioni sopracitate?
(per gopher che ha postato mesi fa... in 
www.hotscripts.com
 ho già guardato 
e non c'era niente di simile)
grazie infinite.

 $t->print($osuser);
Sara' difficile trovare qualcosa di buono perche' sockets in PHP sono ancora
in fase experimental (vedi su 
www.php.net
 i commenti per sockets)... Direi
che sia meglio di usare la tua soluzione in perl a questo punto...
Ma sei vuoi sperimentare qualcosa e non penso che sia difficile farlo (e
provare non costa molto): Se non sbaglio basterebbe mettere i socket in
blocking mode.
www.php.net/set-socket-blocking
 (occhio, pare che non va su win32, quindi
stay linux).
Chiaramente non avresti un modo asynch per decisioni su cosa fare quando il
server non risponde come previsto...
:)
-----------------------------------
E qui la lista delle funzioni non documentate che possono tornare utili:
resource fd_alloc(void)
Allocates a file descriptor set
bool fd_dealloc(void)
De-allocates a file descriptor set
bool fd_set(int fd, resource set)
Adds a file descriptor to a set
bool fd_clear(int fd, resource set)
Clears a file descriptor from a set
bool fd_isset(int fd, resource set)
Checks to see if a file descriptor is set within the file descrirptor
set
void fd_zero(resource set)
Clears a file descriptor set
int select(int max_fd, resource readfds, resource writefds, resource
exceptfds, int tv_sec, int tv_usec)
Runs the select() system call on the sets mentioned with a timeout
specified by tv_sec and tv_usec
int open_listen_sock(int port)
Opens a socket on port to accept connections
bool set_nonblock(int fd)
Sets nonblocking mode for file descriptor fd
int getsockname(int fd, string &addr[, int &port])
Given an fd, stores a string representing sa.sin_addr and the value of
sa.sin_port into addr and port describing the local side of a socket
int gethostbyname(string name, string &addr)
Given a hostname, sets addr to be a human-readable version of the host's
address
int getpeername(int fd, string &addr[, int &port])
Given an fd, stores a string representing sa.sin_addr and the value of
sa.sin_port into addr and port describing the remote side of a socket
int gethostbyaddr(string addr, string &name)
Given a human-readable address, sets name to be the host's name
resource build_iovec(int num_vectors [, int ...])
Builds a 'struct iovec' for use with sendmsg, recvmsg, writev, and
readv
First parameter is number of vectors, each additional parameter is the
length of the vector to create.
string fetch_iovec(resource iovec_id, int iovec_position)
Returns the data held in the iovec specified by
iovec_id[iovec_position]
bool set_iovec(resource iovec_id, int iovec_position, string new_val)
Sets the data held in iovec_id[iovec_position] to new_val
bool add_iovec(resource iovec_id, int iov_len)
Adds a new vector to the scatter/gather array
bool delete_iovec(resource iovec_id, int iov_pos)
Deletes a vector from an array of vectors
bool free_iovec(resource iovec_id)
Frees the iovec specified by iovec_id
int readv(int fd, resource iovec_id)
Reads from an fd, using the scatter-gather array defined by iovec_id
int writev(int fd, resource iovec_id)
Writes to a file descriptor, fd, using the scatter-gather array defined
by iovec_id
int recv(int fd, string buf, int len, int flags)
Receives data from a connected socket
May be used with SOCK_DGRAM sockets.
int send(int fd, string buf, int len, int flags)
Sends data to a connected socket
May be used with SOCK_DGRAM sockets.
int recvfrom(int fd, string &buf, int len, int flags, string &name
[, int &port])
Receives data from a socket, connected or not
int sendto(int fd, string buf, int len, int flags, string addr [, int
port])
Sends a message to a socket, whether it is connected or not
int recvmsg(int fd, resource iovec, array &control, int
&controllen, int &flags, string &addr [, int &port])
Used to receive messages on a socket, whether connection-oriented or
not
int sendmsg(int fd, resource iovec, int flags, string addr [, int port])
Sends a message to a socket, regardless of whether it is
connection-oriented or not
int getsockopt(int fd, int level, int optname, array|int &optval)
Gets socket options for the socket
If optname is SO_LINGER, optval is returned as an array with members
"l_onoff" and "l_linger", otherwise it is an
integer.
int setsockopt(int fd, int level, int optname, int|array optval)
Sets socket options for the socket
If optname is SO_LINGER, optval is expected to be an array
with members "l_onoff" and "l_linger", otherwise it
should be an integer.
int socketpair(int domain, int type, int protocol, array &fds)
Creates a pair of indistinguishable sockets and stores them in fds.
int shutdown(int fd, int how)
Shuts down a socket for receiving, sending, or both.