# A new way called DWS to run php script on nginx 0.8.x!

**URL:** <https://www.ruby-forum.com/t/a-new-way-called-dws-to-run-php-script-on-nginx-0-8-x/196264>\
**Category:** NGINX\
**Created:** [October 10, 2010, 3:43am UTC](https://www.ruby-forum.com/t/a-new-way-called-dws-to-run-php-script-on-nginx-0-8-x/196264 "2010-10-10T03:43:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![hightman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e9bcb4/32.png) [@hightman](https://www.ruby-forum.com/u/hightman)\
**Post date:** [October 10, 2010, 3:43am UTC](https://www.ruby-forum.com/t/a-new-way-called-dws-to-run-php-script-on-nginx-0-8-x/196264/1 "2010-10-10T03:43:47Z")

</div>

PHP-DWS is the abbreviation for “PHP Direct Web Server”. It works much  
like fastcgi server with nginx,

But nginx pass the request header of HTTP and socket file description of  
this connection to it via  
calling sendmsg(), and then PHP-dws read request body data from http  
connection , send response  
data to the http connection directly.

I simply draw their work in the following flow diagramï¼š

```
  [PHP-CGI]
  ============

        i)request header+body ii)request header+body
       + ~~~~>~~~~ > ~~~~>~~~ + + ~~~~~>~~~~~ > ~~~~>~~~~~ +
       | | | |
      /|\ \|/ / \ \|/
  WebVisitor Web Server FastCGIServer
    (user) (nginx) (php-cgi)
      /|\ \ / /|\ \ /
       | | | |
       + ~~~<~~~~ < ~~~~<~~~~ + + ~~~~~<~~~~~ < ~~~~<~~~~~ +
      iv)response header+body iii)response header+body

  [PHP-DWS]
  ============

                    i)request header ii)request header
       + ~~~~>~~~~ > ~~~~>~~~ + + ~~~~~>~~~~~ > ~~~~>~~~~~ +
       | | | |
      /|\ \|/ / \ \|/
  WebVisitor Web Server DWSCGI Server
    (user) (nginx) (php-dws)
   /|\ \ / /|\ \ /
    | | | |
    | + ~~~~~~~~>~~~~~~~~~~~~ > ~~~~~~~~~~~~>~~~~~~~~ + |
    | iii) request body |
    | |
    + ~~~~~~~~~~~~~<~~~~~~~~~~~ < ~~~~~~~~~~~~~<~~~~~~~~~~~~~~ +
    iv)response header+body

```

I think that php-dws will save much more IO operator and become more  
efficient.  
In addition, we can send partial data to browser during script running,  
i.e:  
[http://root.twomice.net/dws-test/sleep.phpd](http://root.twomice.net/dws-test/sleep.phpd)

Welcome to give me some suggestions or comments!

===

I have completed the preliminary work, including two part.

The first is ngx\_http\_dwsgi\_module, download source codes from:  
[http://www.hightman.cn/down/nginx\_0.8\_dwsgi\_module\_beta1.tgz](http://www.hightman.cn/down/nginx_0.8_dwsgi_module_beta1.tgz)

Extract it to top source directory of nginx, it will be looked like:  
nginx-0.8.x/src/addon/dwsgi/

then recompile the nginx with option: --add-module=src/addon/dwsgi

config sample can be found in src/addon/dwsgi/\*.conf

The second is a new sapi module for php, develop under 5.3.3, get the  
source  
code package from:  
[http://www.hightman.cn/down/php53\_sapi\_dws\_beta1.tgz](http://www.hightman.cn/down/php53_sapi_dws_beta1.tgz)

Extract it to top source directory of php5, it will be looked like:  
php-5.3.x/sapi/dws/

then run following commands to rebuild the php:  
./buildconf --force  
./config.nice --disable-fpm --disable-cgi --enable-dws  
make && make install

Run $prefix/bin/php-dwsctl to start or stop php-dws,  
or try $prefix/bin/php-dws -h for more options and its description.

---

<div class="post-metadata">

**Author:** ![hightman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e9bcb4/32.png) [@hightman](https://www.ruby-forum.com/u/hightman)\
**Post date:** [October 10, 2010, 3:43am UTC](https://www.ruby-forum.com/t/a-new-way-called-dws-to-run-php-script-on-nginx-0-8-x/196264/2 "2010-10-10T03:43:47Z")

</div>

Looks great!

ÔÚ 2010Äê10ÔÂ9ÈÕ ÏÂÎç4:47£¬hightman [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) Ð´µÀ£º

---

<div class="post-metadata">

**Author:** ![hightman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e9bcb4/32.png) [@hightman](https://www.ruby-forum.com/u/hightman)\
**Post date:** [October 10, 2010, 3:43am UTC](https://www.ruby-forum.com/t/a-new-way-called-dws-to-run-php-script-on-nginx-0-8-x/196264/3 "2010-10-10T03:43:47Z")

</div>

How does this compare to php-fpm? What are its main benefits? Security?  
Performance? I’d like more comparison points with existing solutions.

---

<div class="post-metadata">

**Author:** ![hightman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e9bcb4/32.png) [@hightman](https://www.ruby-forum.com/u/hightman)\
**Post date:** [October 10, 2010, 3:43am UTC](https://www.ruby-forum.com/t/a-new-way-called-dws-to-run-php-script-on-nginx-0-8-x/196264/4 "2010-10-10T03:43:48Z")

</div>

On Sat, Oct 09, 2010 at 04:47:36PM +0800, hightman wrote:

> ```
> | | | |
> 
> ```
> 
> Welcome to give me some suggestions or comments!  
> What I never liked in unbufferd uploads, when people want to show  
> an upload progress bar, is that a large backend process is tied to  
> a client and the client may upload minutes. Now suppose that the backend  
> process size is 10M and there are 1000 uploading clients: you need 10G.

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![hightman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e9bcb4/32.png) [@hightman](https://www.ruby-forum.com/u/hightman)\
**Post date:** [October 10, 2010, 3:47am UTC](https://www.ruby-forum.com/t/a-new-way-called-dws-to-run-php-script-on-nginx-0-8-x/196264/5 "2010-10-10T03:47:54Z")

</div>

Yes, this is DSR. Thank you very much for your deep advise.

I will try to do more test on it, But I still think that it can save  
much I/O works under good network speed.

ÔÚ 2010-10-9£¬ÏÂÎç6:19£¬ Piotr S. Ð´µÀ£º

---

<div class="post-metadata">

**Author:** ![hightman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e9bcb4/32.png) [@hightman](https://www.ruby-forum.com/u/hightman)\
**Post date:** [October 10, 2010, 5:56am UTC](https://www.ruby-forum.com/t/a-new-way-called-dws-to-run-php-script-on-nginx-0-8-x/196264/6 "2010-10-10T05:56:40Z")

</div>

After careful and extensive testing, the performance of php-dws and  
php-cgi is almost the same,  
Only for large post requests, php-dws slightly better than php-cgi .

However, The main features of php-dws is that response data returned  
directly to user browser.  
In some special case, We may need to deal with long time requests or  
sub-output data according to demand  
such as COMET application, Then you can consider using php-dws!

Thanks all.

åœ¨ 2010-10-9ï¼Œä¸‹åˆ4:47ï¼Œ hightman å†™é“ï¼š

---

<div class="post-metadata">

**Author:** ![hightman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e9bcb4/32.png) [@hightman](https://www.ruby-forum.com/u/hightman)\
**Post date:** [October 10, 2010, 3:46am UTC](https://www.ruby-forum.com/t/a-new-way-called-dws-to-run-php-script-on-nginx-0-8-x/196264/7 "2010-10-10T03:46:08Z")

</div>

Hi,  
it seems that you’re trying to implement DSR (Direct Server Return) on  
application level. There is a lot of disadvantages of DSR:  
[http://devcentral.f5.com/weblogs/macvittie/archive/2008/07/03/3423.aspx](http://devcentral.f5.com/weblogs/macvittie/archive/2008/07/03/3423.aspx)

The single advantage of DSR is the fact that response doesn’t touch  
application router or load-balancer on the way back to the client, which  
allows one to spread traffic over multiple backend servers. However,  
with  
PHP-DWS that won’t be the case because it will work only on the same  
machine  
on which request was accepted.

So I have to ask: what was the reason this was “invented” in the first  
place? Because to be honest I don’t see any advantages of such approach  
over  
HTTP Proxy or FastCGI. It’s not like nginx is so bad at relying response  
back to the client that you need to work around it.

Best regards,  
Piotr S. \< removed\_email\_address@domain.invalid \>
