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

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

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

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

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.

Looks great!

ÔÚ 2010Äê10ÔÂ9ÈÕ ÏÂÎç4:47£¬hightman [email protected] дµÀ£º

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

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.
http://sysoev.ru/en/

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. дµÀ£º

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 写道:

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

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. < [email protected] >