Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:22573 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 78750 invoked by uid 1010); 25 Mar 2006 08:09:17 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 78735 invoked from network); 25 Mar 2006 08:09:17 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Mar 2006 08:09:17 -0000 X-Host-Fingerprint: 67.174.105.139 c-67-174-105-139.hsd1.co.comcast.net Received: from ([67.174.105.139:13388] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id BC/43-11806-DAAF4244 for ; Sat, 25 Mar 2006 03:09:17 -0500 Message-ID: To: internals@lists.php.net Date: Sat, 25 Mar 2006 01:09:23 +0000 Lines: 53 User-Agent: KNode/0.9.0 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Posted-By: 67.174.105.139 Subject: can Php - Fast-CGI and STDIN be used? From: roguestar191@comcast.net (Matthew) 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 php script. I have written a server in c++, which for a while been running php through 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 cgi interface, however, the scripting stuff i had that worked over regular cgi 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 = "%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 = trim(fgets($STDIN)) for a very 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 = processALineFromCGI-OrFastCGIScript(oneLine) if(response.compare("NOCMD") == 0) buffer_to_print_to_user_who_called_this_when_request_finishs(); else if(response.size() > 0) { std::string sendout = 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 second 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!