Re: [PHP] PHP CLI vs WebServed
Replying this back on the list, unchanged and without any additions from me yet. On Sat, Apr 25, 2009 at 14:09, Simon wrote: >> Perhaps you may want to consider hacking PHP itself. From memory, >> one place you may want to start looking is the >> php_filter_get_storage() function, then trace back from there. If >> memory continues to serve correctly, it should be in the >> `ext/filter/filter.c` file. > > Hacking php is probably the most efficient solution, but until i can > accomplish that, i think i got a good idea... > > what if i opened a socket to php with C function popen(), this enables > to read/write to the stdin/out of the called program (php). I would > execute php to read the code from stdin, and the first few lines would > be created by my 'webserver' and would just set all the correct > superglobals ($_GET, $_POST, $_SERVER, etc) overwritting whatever is > in there with the correct information. Then i would add one last line > with something like: > require('theRealPHPfile.php'); > this one would be executed with the proper superglobals set. > > the result would give something similar to: > $_GET['somevar'] = 'somevalue'; > // [...] more superglobals set here... > require('index.php'); > ?> > (end of example) > This is what my program would do when someone tries to browse to: > website.com/index.php?somevar=somevalue > > I see a loss of performance for creating the header, but other than > this, i think it should be almost as efficient as hacking php... and > being easier... > > What do you guys think? > > Thanks! > -- daniel.br...@parasane.net || danbr...@php.net http://www.parasane.net/ || http://www.pilotpig.net/ 50% Off All Shared Hosting Plans at PilotPig: Use Coupon DOW1 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP CLI vs WebServed
On Sat, Apr 25, 2009 at 10:14, Simon wrote: > > Hopefully, I'm looking for a way that would not require any hacking of > the PHP files that are currently working with other webservers... Perhaps you may want to consider hacking PHP itself. From memory, one place you may want to start looking is the php_filter_get_storage() function, then trace back from there. If memory continues to serve correctly, it should be in the `ext/filter/filter.c` file. -- daniel.br...@parasane.net || danbr...@php.net http://www.parasane.net/ || http://www.pilotpig.net/ 50% Off All Shared Hosting Plans at PilotPig: Use Coupon DOW1 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP CLI vs WebServed
Thanks for the reply Richard! > Never done this, but could you set environment variables, which would > then be picked up by PHP (and stuffed in $_ENV)? This seems like a good idea, if i mix this with the popen() idea, i wouldnt need /dev/shm or any files at all then... but the problem remains that the PHP code will need to be setup to get its querystring (and other web-related data) in the $_ENV global instead of whatever was done before (ie using $_GET, $_COOKIES, etc...) I could create a simple function that would set all these globals correctly, copying the info from $_ENV to the proper global var. This function would need to be placed at the begining of any 'main' php files (ie index.php but not in the files it includes). Hopefully, I'm looking for a way that would not require any hacking of the PHP files that are currently working with other webservers... Thanks! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP CLI vs WebServed
Hi, >... Never done this, but could you set environment variables, which would then be picked up by PHP (and stuffed in $_ENV)? -- Richard Heyes HTML5 graphing: RGraph (www.rgraph.net) PHP mail: RMail (www.phpguru.org/rmail) PHP datagrid: RGrid (www.phpguru.org/rgrid) PHP Template: RTemplate (www.phpguru.org/rtemplate) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP CLI vs WebServed
Hi there, I've been using PHP for a very long time now, a few years ago developing webapplications with apache and mysql, now and for a few years using mostly the CLI (mostly as a replacement of all other scripting languages available on linux, sh, pearl, etc...). However, I'm building a project that works very much like a webserver (and does much custom stuff) and i would like to execute php files in a similar way as they are executed by a server like apache. I've been executing php from my C/C++ executable simply by writing the HTTP query string in a temp file (/dev/shm/...) and then executing the php file like so: // usage is: phpfile.php system("php /path/to/phpfile.php /dev/shm/this_executions_querystring.txt /dev/shm/this_execution_output_destination.txt"); But the problem is that this phpfile.php has to be made to read the content of the querystring file to get it, etc... also this design will write the output file to /dev/shm, which is then read and sent my the main program. I'm going to use popen in the future... I'd prefer if i could somehow, on the CLI, set the global variables like $_SERVER and others... this would make it so my software could execute any php file that was built for another webserver transparently. Is this possible on the CLI? Is there a simple way to do what I want? (Btw, the server is already handling all the HTTP packaging/parsing, the problem is really just with the execution) Thanks in advance for any suggestions! Simon -- When Earth was the only inhabited planet in the Galaxy, it was a primitive place, militarily speaking. The only weapon they had ever invented worth mentioning was a crude and inefficient nuclear-reaction bomb for which they had not even developed the logical defense. - Asimov -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php