Tr8n
Tr8n

Reputation: 33

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?

Upvotes: 3

Views: 387

Answers (1)

ebcode
ebcode

Reputation: 306

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.

Upvotes: 1

Related Questions