Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:22595 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 58424 invoked by uid 1010); 27 Mar 2006 12:47:13 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 58409 invoked from network); 27 Mar 2006 12:47:13 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Mar 2006 12:47:13 -0000 X-Host-Fingerprint: 64.233.166.183 pproxy.gmail.com Linux 2.4/2.6 Received: from ([64.233.166.183:1432] helo=pproxy.gmail.com) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 6D/21-37235-1DED7244 for ; Mon, 27 Mar 2006 07:47:13 -0500 Received: by pproxy.gmail.com with SMTP id b36so1341325pyb for ; Mon, 27 Mar 2006 04:47:09 -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=dVoL+BRT8+KdI/fVDLMeTPcN+nBl5OXW+zLKmr1jJLfNqJiCUZMsullnnpnwbbVrXI2aYg3/bZelyWqDJ+SRxzyAkfDSFylZIS/nMe4AqVWFhQs15gMHHgwDZDSVCUEKRHiFvU91OgB7utvphjir8GwgOhNOZx4tBJMlR+08XVw= Received: by 10.35.77.18 with SMTP id e18mr618988pyl; Mon, 27 Mar 2006 04:47:09 -0800 (PST) Received: by 10.35.41.17 with HTTP; Mon, 27 Mar 2006 04:47:09 -0800 (PST) Message-ID: <4e89b4260603270447v5e9af12fw586b34a756d3cdab@mail.gmail.com> Date: Mon, 27 Mar 2006 07:47:09 -0500 To: Matthew Cc: internals@lists.php.net In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: Subject: Re: [PHP-DEV] can Php - Fast-CGI and STDIN be used? From: kingwez@gmail.com ("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 whe= re > else to go. > > I need some help figuring out how to use FCGI_STDIN with a running php > script. > > I have written a server in c++, which for a while been running php throug= h > 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 the cg= i > interface, however, the scripting stuff i had that worked over regular cg= i > just doesn't want to work with fast-cgi. > > Basically, the php script outputs a command and arguments, all commands > 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 strings= of > data over stdin so they can be $var =3D trim(fgets($STDIN)) for a very si= mple > 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 secon= d > port to pipe requests from php streams to the server, but would be a MAJO= R > 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 > >