# adding support for PHP to a web server

- Thread: https://externals.io/message/42935
- Original archive: https://news-web.php.net/php.internals/42935
- Started by Terry Braun on 2009-02-05T15:12:38+00:00
- Messages: 8
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #42935 — Terry Braun — 2009-02-05T15:12:38+00:00

URL: https://externals.io/message/42935#42935

Hello,
I've written a small web server and I'd like to add support for php to 
the server. Could anyone direct me to documentation or examples and give 
me some sense of how hard this would be. Put another way, if I have a 
working PHP installation and a web server how do the two communicate?

The webserver is written in javascript running on rhino which in turn 
runs on java so probably the access would be through java.

Thanks
Terry

---

## #42936 — Alexey Zakhlestin — 2009-02-05T15:18:36+00:00

URL: https://externals.io/message/42935#42936 · In reply to: #42935

> Hello,
> I've written a small web server and I'd like to add support for php to the
> server. Could anyone direct me to documentation or examples and give me some
> sense of how hard this would be. Put another way, if I have a working PHP
> installation and a web server how do the two communicate?
>
> The webserver is written in javascript running on rhino which in turn runs
> on java so probably the access would be through java.

The most simple way is to use cgi or fastcgi protocol. I think, there
should be some java-libraries implementing that

-- 
Alexey Zakhlestin
http://www.milkfarmsoft.com/

---

## #42937 — Kalle Sommer Nielsen — 2009-02-05T16:08:20+00:00

URL: https://externals.io/message/42935#42937 · In reply to: #42935

Hello

2009/2/5 Terry Braun <tab@talking.com>:
> Hello,
> I've written a small web server and I'd like to add support for php to the
> server. Could anyone direct me to documentation or examples and give me some
> sense of how hard this would be. Put another way, if I have a working PHP
> installation and a web server how do the two communicate?

Currently theres no SAPI documentation, however like Alexey said it
would probably be easier to just the cgi/fastcgi protocol.

>
> The webserver is written in javascript running on rhino which in turn runs
> on java so probably the access would be through java.
>
> Thanks
> Terry



-- 
Kalle Sommer Nielsen

---

## #42940 — johannes@schlueters.de — 2009-02-05T16:37:53+00:00

URL: https://externals.io/message/42935#42940 · In reply to: #42937

Hi,


> Currently theres no SAPI documentation, however like Alexey said it
> would probably be easier to just the cgi/fastcgi protocol.

There's a chapter in Sara's book. sapi/embed is a quite simple example
of an SAPI. But I agree (Fast)GI sounds like a saner way,else you'd have
to provide some C wrapper giving you some APIs you can use from your
Java code. Directly using PHP APIs via JNI doesn't really sound like
fun.

johannes

---

## #42951 — Andrew Rose — 2009-02-05T20:14:03+00:00

URL: https://externals.io/message/42935#42951

2009/2/5 Terry Braun <tab@talking.com>:
> Thanks to everyone for the help. One last hopefully quick and not too naive
> question - can I just exec php and pipe input and output? There is probably
> some good reason that is not obvious to me.
> terry

Some reasons would be:

* limited $_SERVER environment
* No $_GET, $_POST, $_REQUEST or $_COOKIE
* headers() will be of no use
* sessions would be a challenge to implement (because there is no
access to headers for cookies)


-
Andrew Rose
http://andrew-rose.blogspot.com

---

## #42952 — johannes@schlueters.de — 2009-02-05T20:21:34+00:00

URL: https://externals.io/message/42935#42952

> Thanks to everyone for the help. One last hopefully quick and not too 
> naive question - can I just exec php and pipe input and output? There is 
> probably some good reason that is not obvious to me.
> terry

that's basically what CGI does, while the CGI standard defines some
environmental variables you should set (lie QUERY_STRING which will be
parsed into PHP's $_GET array) See http://www.w3.org/CGI/

johannes

---

## #42955 — Stanislav Malyshev — 2009-02-05T21:07:26+00:00

URL: https://externals.io/message/42935#42955

Hi!

> naive question - can I just exec php and pipe input and output? There is 
> probably some good reason that is not obvious to me.

The good reasons for using FCGI are:
- environment passing
- headers handling
- POST passing
- stderr handling
- performance - creating new process is very expensive
- structure - people already thought about a bunch of things when 
creating this protocol that may not be obvious at first
- wide support - a lot of FCGI implementations exist, both server and client

There's also SCGI which is much simpler than FCGI but no official PHP 
driver for it yet (it's really so simple you could probably implement it 
in PHP too, but lose some of the advantages).
-- 
Stanislav Malyshev, Zend Software Architect
stas@zend.com   http://www.zend.com/
(408)253-8829   MSN: stas@zend.com

---

## #42957 — Stefan Marr — 2009-02-05T21:40:37+00:00

URL: https://externals.io/message/42935#42957 · In reply to: #42935

Hi,

just a suggestion, have you thought about using Quercus [http://www.caucho.com/resin-3.0/quercus/ 
]
or Project Zero [http://www.projectzero.org/download/]?

This projects are implementing PHP in Java.

Regards
Stefan



> Hello,
> I've written a small web server and I'd like to add support for php  
> to the server. Could anyone direct me to documentation or examples  
> and give me some sense of how hard this would be. Put another way,  
> if I have a working PHP installation and a web server how do the two  
> communicate?
>
> The webserver is written in javascript running on rhino which in  
> turn runs on java so probably the access would be through java.
>
> Thanks
> Terry
