Effectively run G'MIC in PHP?

Hello, I am trying to use G’MIC to generate captchas for my website, which by starting the program every time does work. However, the problem is, that the overhead of starting the program on each request is immense. If I wrote a custom webserver in C, I could use the libgmic library. So, is there an effective way to keep the G’MIC interpreter running and funnel data into it from PHP?

bump?

I don’t know if any one here can help you as there’s almost no one with experience with PHP. What I can do is to suggest a loop to execute G’MIC to generate your captcha. As far as data goes, G’MIC isn’t designed to share data between applications, but there are workaround like using names in context of captcha. There might be something with exec command in G’MIC to try to bridge communication.

Why dynamic? Just generate them in larger batches via cron+shell. Delete after use from PHP. Generate more when running low. That should take 30min to implement. Ensure the writing is atomic (temp file + mv), so PHP doesn’t read a half generated captcha by chance.

…or sockets, but that’s at least 3 days of coding. How to IPC between PHP clients and a C Daemon Server? - Stack Overflow

Oh, that’s a nice solution, hadn’t thought of that. Thanks!

You could also use the GMIC C bridging library. It does not require any additional dependencies (not even to GMIC) and allows you to integrate GMIC directly in your C/C++ application.