如何整合PHP和C程序? [英] How to integrate PHP and C program?

查看:102
本文介绍了如何整合PHP和C程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我把我的问题在一个简单的方法。我已经写了一个C程序,我会保持我的服务器。现在我开发
使用PHP的网站,以便其他用户也可以访问我的独立的C程序。

Let me put my problem in a simple way. I have written a C program, which i will keep in my server. Now i am developing a website using PHP, so that other users can also have access to my stand alone C program.

所以在这里,我想我的PHP从用户那里接受输入,并把输入和运行我的C程序,然后再取结果
C程序返回到使用PHP的用户(可能使用相同的网站本身)。

So here i want my PHP to take input from users and bring that input and run my C program and then again take the results of the C program back to the users using PHP(probably using the same website itself).

请建议我该怎么做。这将是我更容易理解,如果你可以用简单的程序告诉我。
比如我的C程序有一个功能,增加了两个数字。用户可以使用其提供输入(数字)我
网站。然后PHP会以某种方式与C函数进行互动,并将结果返回给用户。

Please suggest me how to do it. It would be easier for me to understand if you can tell me using simple program. For example my C program has a function that adds two numbers. The users can provide their input (the numbers) using my website. Then PHP will somehow interact with C function and return the results to the user.

推荐答案

只需使用PHP的exec命令。我假设你有机会获得实际的C可执行文件。
http://www.php.net/manual/en/function.exec.php

Just use the php exec command. I'm assuming you have access to the actual C executable. http://www.php.net/manual/en/function.exec.php

<?php
// outputs the username that owns the running php/httpd process
// (on a system with the "whoami" executable in the path)
echo exec('whoami');
?>

这篇关于如何整合PHP和C程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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