如何向编译器发送http请求 [英] How to send http request to compiler

查看:136
本文介绍了如何向编译器发送http请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Csharp开发一个Web服务器,我想在其上安装php编译器。

I'm developing a web server in Csharp and I want to install php compiler on it.

当前状态:Web服务器正在工作并接收连接,可以编译PHP页面,我正在使用 procces start 调用PHP编译器,我可以像这样arg发送GET参数:

Current state: the web server is working and receiving connection, can compile PHP pages, I'm invoking PHP compiler using procces start and I can send GET parameters as arg like that:

php.exe name=1 /index.php 

问题是如何以更好的方式将post,get data和HTTP header发送给编译器?

The problem is how to send post, get data and HTTP headers to the compiler in such better way?

推荐答案

确实存在在命令行界面上传递HTTP标头的相当苛刻的解决方案: -B - process-begin 标志允许在相关脚本之前运行代码。这可用于将数据注入 $ _ SERVER 超全局数组,用于模拟正在设置的标头。例如。要设置 X-Foo:bar ,你可以运行:

There is indeed a rather hackish solution to pass HTTP headers on the command-line interface: The -B or --process-begin flag allows for code to be run before the script in question. This could be used to inject data into the $_SERVER superglobal array to simulate headers being set. E.g. for X-Foo: bar to be set, you would run this:

php.exe --process-begin '$_SERVER["HTTP_X_FOO"] = bar;' /index.php

使用 $ _ GET $ _ POST superglobals也可以这样做。然而,这真的只是一个黑客,出于安全原因,我不能在学术环境之外推荐这个。

The same can be done with the $_GET and $_POST superglobals. However, this really is just a hack and I cannot recommend this outside of academic environments for security reasons.

一个稍好的方法是利用内置网络服务器。如果您已经足够干净地编码,那么将传入的请求重新路由到PHP并将结果反馈回来应该没有问题。但是,如果您不需要任何虚拟主机,这将只能完美地工作。和上面的解决方案一样,这在研究之外没有其他地方!

A slightly better way were to take advantage of the builtin webserver. If you have coded cleanly enough, it should be no problem to reroute incoming requests to PHP and channel the result back. This will only work flawlessly if you do not require any virtualhosts, though. And as with the solution above, this has no place outside of research!

绝对正确的方法是实现通用网关接口。 PHP本身带有一个CGI接口,所以说CGI就是琐碎的。如果遇到可伸缩性问题,您可能需要切换到 FastCGI 。可以在此处找到示例实现。

The absolute correct way were to implement the Common Gateway Interface. PHP comes with a CGI interface itself, so speaking CGI to it is trivial. If you run into scalability problems, you may want to switch to FastCGI. A sample implementation can be found here.

最后一件事:PHP是一种解释语言,而不是编译过的语言。

One last thing: PHP is an interpreted language, not a compiled one.

这篇关于如何向编译器发送http请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆