Answer the question
In order to leave comments, you need to log in
How to write a PHP extension to work with a console program?
Hello.
There is a console program for morphological text analysis https://tech.yandex.ru/mystem/.
Working with the program from the console is elementary: ./mystem -lwd in.txt out.txt
I need to perform morphological analysis of the text using PHP tools, I cannot use the exec () function.
The easiest way is to write text to a file using PHP, then analyze it using a bash script and cron and save it to another file.
But I would like a more convenient option in the form of the PHP function mystem(string, param).
I can compile and install extensions, but I can't write them.
It seems to me that the task is very simple, because maybe someone has come across a solution to a similar problem and is there a "fish"?
In total, my question sounds like this, does anyone have a ready-made solution in which you can only change the name of the console program and there will be a ready-made extension? Thank you!
Answer the question
In order to leave comments, you need to log in
Based on pure logic, it is unlikely that anyone else had such an idiotic task when exec cannot be performed, but you can connect your extension.
I would use queues, let the PHP script add jobs to the database, and some external handler written in any language reads the jobs, processes them, adds the results to a file and updates the status.
Can proc_open be used? There is a wrapper here https://github.com/aotd1/mystem , it executes via proc_open.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question