note 76856 added to function.stream-socket-pair
| From: | Till at osu1 dot php dot net | Date: | Thu, 02 Aug 2007 15:47:38 +0000 |
| Subject: | note 76856 added to function.stream-socket-pair | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-129127@lists.php.net to get a copy of this message | ||
This is some freak-example how to use this feature to fork to a
bc-command on a Solaris-Server:
<?
$sockets=stream_socket_pair(STREAM_PF_UNIX,STREAM_SOCK_STREAM,
STREAM_IPPROTO_IP);
passthru('
perl -e \'
use strict; my ($x,@x);
open(STDIN,"-|","/bin/pfiles $$");
while (<>) { $x=$1 if(/^ +([0-9]+):/); push(@x,$x) if(/AF_UNIX/); }
print "Starting bc -l 0<&$x[1] 1>&$x[1] $x[0]<&- $x[0]>&-
...\n\n";
exec("bash","-c","bc -l 0<&$x[1] 1>&$x[1]
$x[0]<&- $x[0]>&- &");\'');
fclose($sockets[0]);
fwrite($sockets[1],"666*999\n");
print "666*999 = ".fgets($sockets[1])."\n";
fwrite($sockets[1],"./696\n");
print "./696 = ".fgets($sockets[1])."\n";
fwrite($sockets[1],"quit\n");
fclose($sockets[1]);
?>
The big problem is, that there seems to be no way to obtain the real
filedescriptors of the two sockets, but you need them, if you want to
redirect some program's STDOUT and STDIN to one of these sockets.
I misused the /bin/pfiles command on a Solaris UNIX to find them.
Another (non-php-) problem is, that, if you use php in Apache, there
will be already a lot of open filedescriptors and the filedescriptors
of the sockets will be greater than 9. That's why I had to use the bash.
I think it is awful, but it works. Would be great, if someone
would come up with a better idea.
----
Server IP: 64.71.164.2
Probable Submitter: 88.217.195.82
----
Manual Page -- http://www.php.net/manual/en/function.stream-socket-pair.php
Edit -- https://master.php.net/note/edit/76856
Del: integrated -- https://master.php.net/note/delete/76856/integrated
Del: useless -- https://master.php.net/note/delete/76856/useless
Del: bad code -- https://master.php.net/note/delete/76856/bad+code
Del: spam -- https://master.php.net/note/delete/76856/spam
Del: non-english -- https://master.php.net/note/delete/76856/non-english
Del: in docs -- https://master.php.net/note/delete/76856/in+docs
Del: other reasons-- https://master.php.net/note/delete/76856
Reject -- https://master.php.net/note/reject/76856
Search -- https://master.php.net/manage/user-notes.php