Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:22612 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 50394 invoked by uid 1010); 29 Mar 2006 01:31:48 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 50379 invoked from network); 29 Mar 2006 01:31:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Mar 2006 01:31:48 -0000 X-Host-Fingerprint: 64.233.166.182 pproxy.gmail.com Linux 2.4/2.6 Received: from ([64.233.166.182:31762] helo=pproxy.gmail.com) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id C6/48-14993-383E9244 for ; Tue, 28 Mar 2006 20:31:47 -0500 Received: by pproxy.gmail.com with SMTP id e30so179345pya for ; Tue, 28 Mar 2006 17:31:45 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=CUSsrnN2ZZJgxx5SiVE0IcueNWpxKibZE9M6QlowsFmSFE2V3P891Ldo8Lz2LSlC5gf2ec8wzHgKCAzeCsl3jxtzlituZlk7EcKWj3Ib3p6yTbcIQ4brKvGsoc7p/GFKRfxjMaZQPsDs0CNXj1+wGRgm7NtRG/iypJaG/UKX6aw= Received: by 10.35.109.2 with SMTP id l2mr145858pym; Tue, 28 Mar 2006 17:31:45 -0800 (PST) Received: by 10.35.41.17 with HTTP; Tue, 28 Mar 2006 17:31:45 -0800 (PST) Message-ID: <4e89b4260603281731n13ee3f57u7f52d5107529e08b@mail.gmail.com> Date: Tue, 28 Mar 2006 20:31:45 -0500 To: "roguestar191@comcast.net" Cc: internals@lists.php.net In-Reply-To: <032820062059.19729.4429A3AC0005601D00004D112200762194CEC7CE9D0E9B9C0A9A09019D@comcast.net> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <032820062059.19729.4429A3AC0005601D00004D112200762194CEC7CE9D0E9B9C0A9A09019D@comcast.net> Subject: Re: [PHP-DEV] can Php - Fast-CGI and STDIN be used? From: kingwez@gmail.com ("Wez Furlong") If you're that familiar with the fcgi spec, then you'll realize that a simple dup2() is not sufficient. It's still better to tackle the problem "the right way" instead of trying to force something to work in a way that it doesn't. Hence the term "abuse". Advocating the use of threads to "solve" this is also a bad idea, likewise, where are you going to fit the dispatcher for multiplexing? Take my advice: take a step back, take a deep breath and look at the problem again, and remember: KISS. --Wez. On 3/28/06, roguestar191@comcast.net wrote: > sorry the word abuse pissed me off. I'm not abusing anything the protocol= s weren't designed to support (even if they don't know it, but then, they d= o know it). I can understand if nobody ever thought of this use of it befor= e and is why there is no support for using fcgistdin with php, even tho an= y other programming language can use it if it properly and _fully_ supports= the fast-cgi protocol. > > The easiest way I can think of to make a fast-cgi client application woul= d be to simple close socket 0, and socket 1 (stdin and stdout), then dup2in= g to the end of a pipe, cout data would be grabbed from the end of one of t= he pipes, wrapped in a fast-cgi header, printed to the server, stdin data f= rom the server would come in to a second thread (or a multiplexing select()= core), using the request id it finds the proper stdin pipe and just sends = the data there. > > That's not hard to do, that's not off from the fast-cgi protocol, that's = not an abuse, and that would allow the very simple stdin/stdout protocols t= o work for the easiest, most extendable server scripting ever convieved. > > -------------- Original message -------------- > From: "Wez Furlong" > > > IMO, you're better off using stream_socket_server() and writing a > > "real" daemon for that. Abusing fastcgi/cgi to work in that way is > > only going to bite you in the ass. > > > > --Wez > > > > On 3/24/06, Matthew wrote: > > > I'm sorry if this is the wrong place for this post, I just don't know= where > > > else to go. > > > > > > I need some help figuring out how to use FCGI_STDIN with a running ph= p > > > script. > > > > > > I have written a server in c++, which for a while been running php th= rough > > > it's plain old cgi interface. I have been using php for 2 things, the > > > obvious one, web pages, and the not so obvious, safe command/server > > > scripting. I have just implimented a fast-cgi interface to replace th= e cgi > > > interface, however, the scripting stuff i had that worked over regula= r cgi > > > just doesn't want to work with fast-cgi. > > > > > > Basically, the php script outputs a command and arguments, all comman= ds > > > start with a %, so: > > > $var =3D "%print"; > > > printf("%s hello world\n", $var); > > > Can be used to print to the user calling the script. > > > > > > That part still works fine of course :). > > > > > > It doesn't stop there however, some of the %callbacks will return str= ings of > > > data over stdin so they can be $var =3D trim(fgets($STDIN)) for a ver= y simple > > > and effective method of communicating with the server. > > > > > > I've tried doing the same with fast-cgi, but it seems > > > fopen("php://stdin","r") is not the right place to be reading from. > > > > > > I'm sending: > > > > > > (C++) > > > // loops over ever line of input, test it > > > std::string response =3D processALineFromCGI-OrFastCGIScript(oneLine) > > > if(response.compare("NOCMD") =3D=3D 0) > > > buffer_to_print_to_user_who_called_this_when_request_finishs(); > > > else if(response.size() > 0) { > > > std::string sendout =3D FCGI_Headerize(response, FCGI_STDIN, ..); > > > non-blocking_send(sendout); > > > } > > > oneLine.erase(); > > > I use the same function to build the headers for FCGI_BEGIN_REQUEST, > > > FCGI_PARAMS, FCGI_STDIN on POST input, it works great there(now) > > > > > > > > > Also, is it possible to keep the connection open to php-cgi to avoid > > > connect/accept calls? Even if it's only fifo so only 1 request can go= at a > > > time? > > > > > > If I must I could create a special c++ fast-cgi server that binds a s= econd > > > port to pipe requests from php streams to the server, but would be a = MAJOR > > > hack for what I'm trying to do.. :-D > > > > > > Thanks in advance! > > > > > > -- > > > PHP Internals - PHP Runtime Development Mailing List > > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > >