简体   繁体   中英

Calling C program with PHP

I've written a small database engine in C that works by reading commands you input in the console and it outputs the result. Is there any way of me writting some PHP code that could send arguments to the console and recieve the output back to PHP without restarting the compiled program. Is there a better way of doing this?

You say you want the PHP to send and receive messages to your program without restarting the compiled program.

So I don't think using shell_exec or proc_open will work how you want, since these commands both load a fresh instance of the compiled program.

Instead, I suggest you look into sockets , and how you would rewrite your database engine to use those instead of STDIN/STDOUT. Then you can use PHP's socket functions to communicate between your applications. And you'll have just one instance of your compiled program running in the background, even with multiple hits to your PHP script.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM