How to set http response header when php is used with g-wan

China☆狼群 提交于 2019-12-13 19:25:21

问题


I add the header function in the hello.php sample, as below:

<?php
   header("xxxxx: yyyyy");
   fwrite(STDOUT, "see headers.<br><br>Hello, PHP!<br>current working directory: ".getcwd());
   exit(200); // return an HTTP code (200:'OK')
?>

but there is no such header found in firebug.
Who can explain how to add additional headers in php cli with gwan?


回答1:


Thanks to Gil and Richard,
Now, it is what i did according to your advices. PHP works in gwan with customized headers.

<?php
 $output='See headers....Hello, PHP!<br>from gwan';
   $len=strlen($output);
   fwrite(STDOUT, "HTTP/1.0\r\nContent-Type: text/html; charset=UTF-8\r\nConnection: close\r\nContent-Length: $len\r\nxxxxx: yyyyy\r\n\r\n$output");
    exit(1);
?>

i use ab -c 1000 -n 100000 http:127.0.0.1/?hello.php
The memory usage is increased by 0.7% of 2.9GiB = 0.0203GiB
The CPU usage is increased from 20% to 75% = 50% (ab run in the same machine with gwan)
I did it in my old machine intel P9300 2.26GHz x 2, ubuntu 12.04

it finished in 9.543 sec without failure
about 10,479 req/sec




回答2:


Tom is right. To bypass the HTTP headers injected by G-WAN (because you returned 200) you should return a value in the 1-99 range (an invalid HTTP status code).

Then, you own HTTP headers (if any) will be used.

return 0; means close connection and return 200-600; is reserved for HTTP return codes that tell G-WAN to generate the correspondig HTTP headers.

The PDF manual is a resource worth reading.


Just a word about "fastCGI": it will NEVER be faster than running scripts in parallel from several threads... without ever involving the network (between the server and PHP).

The more intermediate layers or interfaces you add, the slower things will be so as "fastCGI" runs scripts via an interface using the network is necessarily slower than running the code directly (and I am not even addressing the fact that the PHP "fastCGI" server is very slow, that the fastCGI protocol iself is pointlessly complex and therefore slow, and that, on the top of that, the fasctCGI implementation is more than sub-optimal).

Now we have multicore CPUs, parallelism does not necessarily involve HORIZONTAL scalability (the scalability obtained by running code on many connected machines).

It is way cheaper (faster and more energy efficient) to scale VERTICALLY (on the many CPU Cores that reside on the local machine).

As the number of CPU Cores is growing exponentially, there is no way back: scaling VERTICALLY will make more and more sense as time goes.



来源:https://stackoverflow.com/questions/14457373/how-to-set-http-response-header-when-php-is-used-with-g-wan

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!