A
A
Anton B2015-04-01 12:21:08
linux
Anton B, 2015-04-01 12:21:08

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

3 answer(s)
F
FanatPHP, 2015-04-01
@FanatPHP

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.

K
Komly, 2015-04-01
@Komly

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.

A
Alexander Talalaev, 2015-04-01
@neuotq

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 question

Ask a Question

731 491 924 answers to any question