Re: [PHP-DEV] How to integrate PHP with my homegrown server

2007-08-24 Thread Robert Cummings
On Fri, 2007-08-24 at 11:08 -0400, Steve Francisco wrote:
 Hi, as an experiment I have a simple Java based server that listens on 
 port 80 and can serve files just fine.  I'd like to extend it to support 
 PHP but am looking for guidance on how to do that.  Can someone point me 
 to instructions?
 
 My first attempt was to just call the php.exe command line interface to 
 launch the php interpreter, capture the html and send it back to the 
 caller.  That works well, but I can't seem to figure out how to deal 
 with parameters.  For example, if the url would be this on the server:
  http://some.server.com/mypage.php?parm1=Helloparm2=Goodbye
 and in mypage.php I do something like this:
  $echo $_GET[parm1];
 then how do I test this via the PHP command line?
 
 If the command line doesn't have a way to cause $_GET to be populated, 
 then what other way of invoking PHP could I use?

Sounds like you might need some glue. Have your PHP script run a
function that synchs up the globals with what you want. So your Java
server could populate a file or something with the appropriate data that
it received and your glue function would read it and populate the global
arrays.

Cheers,
Rob.
-- 
...
SwarmBuy.com - http://www.swarmbuy.com

Leveraging the buying power of the masses!
...

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] How to integrate PHP with my homegrown server

2007-08-24 Thread Mikko Koppanen
On 8/24/07, Robert Cummings [EMAIL PROTECTED] wrote:

 On Fri, 2007-08-24 at 11:08 -0400, Steve Francisco wrote:
  Hi, as an experiment I have a simple Java based server that listens on
  port 80 and can serve files just fine.  I'd like to extend it to support
  PHP but am looking for guidance on how to do that.  Can someone point me
  to instructions?
 
  My first attempt was to just call the php.exe command line interface to
  launch the php interpreter, capture the html and send it back to the
  caller.  That works well, but I can't seem to figure out how to deal
  with parameters.  For example, if the url would be this on the server:
   http://some.server.com/mypage.php?parm1=Helloparm2=Goodbye
  and in mypage.php I do something like this:
   $echo $_GET[parm1];
  then how do I test this via the PHP command line?
 
  If the command line doesn't have a way to cause $_GET to be populated,
  then what other way of invoking PHP could I use?

 Sounds like you might need some glue. Have your PHP script run a
 function that synchs up the globals with what you want. So your Java
 server could populate a file or something with the appropriate data that
 it received and your glue function would read it and populate the global
 arrays.

 Cheers,
 Rob.
 --
 ...
 SwarmBuy.com - http://www.swarmbuy.com

 Leveraging the buying power of the masses!
 ...

 --
 PHP Internals - PHP Runtime Development Mailing List
 To unsubscribe, visit: http://www.php.net/unsub.php


You could take a look at implementing PHP support via CGI.


-- 
Mikko Koppanen


Re: [PHP-DEV] How to integrate PHP with my homegrown server

2007-08-24 Thread Daniel Brown
On 8/24/07, Steve Francisco [EMAIL PROTECTED] wrote:
[snip!]
 If the command line doesn't have a way to cause $_GET to be populated,
 then what other way of invoking PHP could I use?
 -- Steve

Steve,

You'd need to transpose the $_GET variables from the request to
$argv variables via the CLI.  I don't know exactly how Java would
handle it, but the PHP equivalent (though rather recursive and
unnecessary, it's just here for demonstration purposes) would be:

?
foreach($_GET as $p = $v) {
$data .=  .$p.=.$v;
}
exec('`which php` '.$filename.$data,$ret); // This would work on Linux
// exec('X:\path\to\php.exe '.$filename.$data,$ret);
?

Then, in the PHP script, if it wants $_GET variables, you simple
reverse-transpose the variables like so:

?
// cliscript.php
// Test this from the CLI like so:
// php cliscript.php nothing=nill apple=orange foo=bar testvar=itworks

for($i=1;$icount($argv);$i++) {
$variables = split(=,$argv[$i]);
$_GET[$variables[0]] = $variables[1];
}

echo $_GET['testvar'].\n;
?


Of course, remember to sanitize all of your input properly.
Someone else will probably provide a better example than this in some
way, but in the interest of a quick reply, that will get you started.

-- 
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107

Hey, PHP-General list
50% off for life on web hosting plans $10/mo. or more at
http://www.pilotpig.net/.
Use the coupon code phpgeneralaug07
Register domains for about $0.01 more than what it costs me at
http://domains.pilotpig.net/.

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] How to integrate PHP with my homegrown server

2007-08-24 Thread Steve Francisco

Daniel Brown wrote:

On 8/24/07, Steve Francisco [EMAIL PROTECTED] wrote:
[snip!]

If the command line doesn't have a way to cause $_GET to be populated,
then what other way of invoking PHP could I use?
-- Steve


Steve,

You'd need to transpose the $_GET variables from the request to
$argv variables via the CLI.  I don't know exactly how Java would
handle it, but the PHP equivalent (though rather recursive and
unnecessary, it's just here for demonstration purposes) would be:

Thanks Daniel, I can certainly do that in Java without much trouble, 
however I was hoping to avoid needing to do things in each php file to 
convert argv into $_GET.  I want to be able to serve standard PHP 
without modifying each one.


But you made me realize there is a way.  I wrote a small pre.php file 
like this:

?php
#
for($i=1;$icount($argv);$i++) {
$variables = split(=,$argv[$i]);
$_GET[$variables[0]] = $variables[1];
}
?

and in my php.ini, I set this:
auto_prepend_file =e:\php523\pre.php

Now it works fine without having to modify the php code!  All I need to 
do is have the Java code set up the html parms as argv, and I'm done.

-- Steve

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] How to integrate PHP with my homegrown server

2007-08-24 Thread Daniel Brown
On 8/24/07, Steve Francisco [EMAIL PROTECTED] wrote:
[snip!]
 Thanks Daniel, I can certainly do that in Java without much trouble,
 however I was hoping to avoid needing to do things in each php file to
 convert argv into $_GET.  I want to be able to serve standard PHP
 without modifying each one.

 But you made me realize there is a way.  I wrote a small pre.php file
 like this:
 ?php
 #
 for($i=1;$icount($argv);$i++) {
 $variables = split(=,$argv[$i]);
 $_GET[$variables[0]] = $variables[1];
 }
 ?

 and in my php.ini, I set this:
 auto_prepend_file =e:\php523\pre.php

 Now it works fine without having to modify the php code!  All I need to
 do is have the Java code set up the html parms as argv, and I'm done.
 -- Steve

That was actually what I was getting at, but because I went to
test it on my own box to be certain it would work, I apparently forgot
to type it into the email.

-- 
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107

Hey, PHP-General list
50% off for life on web hosting plans $10/mo. or more at
http://www.pilotpig.net/.
Use the coupon code phpgeneralaug07
Register domains for about $0.01 more than what it costs me at
http://domains.pilotpig.net/.

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] How to integrate PHP with my homegrown server

2007-08-24 Thread BuildSmart

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1


On Aug 24, 2007, at 11:22:14, Robert Cummings wrote:


On Fri, 2007-08-24 at 11:08 -0400, Steve Francisco wrote:
Hi, as an experiment I have a simple Java based server that  
listens on
port 80 and can serve files just fine.  I'd like to extend it to  
support
PHP but am looking for guidance on how to do that.  Can someone  
point me

to instructions?

My first attempt was to just call the php.exe command line  
interface to

launch the php interpreter, capture the html and send it back to the
caller.  That works well, but I can't seem to figure out how to deal
with parameters.  For example, if the url would be this on the  
server:

 http://some.server.com/mypage.php?parm1=Helloparm2=Goodbye
and in mypage.php I do something like this:
 $echo $_GET[parm1];
then how do I test this via the PHP command line?

If the command line doesn't have a way to cause $_GET to be  
populated,

then what other way of invoking PHP could I use?


Sounds like you might need some glue. Have your PHP script run a
function that synchs up the globals with what you want. So your Java
server could populate a file or something with the appropriate data  
that
it received and your glue function would read it and populate the  
global

arrays.


Would it not be easier to build php as a cgid?

You can look at the source in lighttpd, it shows an simple method to  
interface with the php cgid which I think you could incorporate into  
your java server (unless your java server is all script based then it  
might take a little more work).




Cheers,
Rob.


- -- BuildSmart

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.2.2 (Darwin)

iD8DBQFGzxsv0hzWbkf0eKgRAvb6AKCqlvNucj+YQtnEyENYbwkAKMCnTQCbBDSF
CGhKu8kbc2OQy8CTsLlN+kY=
=C7+d
-END PGP SIGNATURE-

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php