1

我要做的是:让服务器携带一个分析图片(发送到Web服务器)并返回结果的程序,该程序已经存在并且是用C#和C++编写的。出于兴趣,该程序分析图案/网格以确定金属物体上施加了多少压力,并且分析时间不超过一秒钟。

我想知道:

  1. 如何将程序存储在 Web 服务器上(或者如何存储它以便我可以从 Web 服务器访问它)?
  2. 如何通过网络服务器调用程序?
  3. 我想上面需要使用 PHP 等语言进行一些编程,但是这段代码是在哪里编写/执行的?
4

2 回答 2

1

我真的会在网络服务器级别使用 PHP 来做到这一点。

PHP 有一个名为shell_exec. 该命令可以调用程序。

$result = shell_exec("./your_program ".escapeshellargs($image_path));

在webserver有权限执行程序的情况下(应该是chmod mode 755)。

(Ps 这应该在 *nix 上工作,对于 Windows 我不确定)

(如果你不能在服务器上编译你的程序,交叉编译然后上传)

于 2013-04-24T08:47:06.440 回答
0

The simple solution to this problem is the run your program synchronously inside your web request (this means that your web page has to wait for the program to deliver its results). This means that, in your PHP page (or a controller, if you are using an MVC-like architecture) you use system() or similar to run your program on the server. This will probably output results to standard output, or maybe to a file or a database. If your program takes a second to run, this is probably an acceptable delay, as long as you have a low number of users.

To do this:

  • Store your console program somewhere on the server, "C:\My Programs\My Analyser\Analyser.exe" is fine.
  • You should know the path location of your image file. You can then pass that pathname as a parameter to your console program.
  • You can then retrieve the results of the call, either from stdout or elsewhere, depending on how your console program returns its analysis

That said, a better way to run this it is to run a job server, so that your program is run asynchronously (this means that your job server accepts a request to run the program, and it will be run when a slot becomes free). This will mean your web page will run faster, and your server won't get overloaded with too many people running your program at the same time. The downside is that the architecture of your system is more complicated, and you'll have to change your UI to cope with unprocessed jobs.

If you are interested in setting up a job server, consider something like Gearman. You'll have to poll the server to see if a job has been processed, or have your job process write a completion flag to your database, which can be checked trivially by your web script.

于 2013-04-24T15:10:46.123 回答