dqef7931 2018-06-11 22:44
浏览 154
已采纳

通过PHP执行linux命令

I am using the tool for language analysis called Freeling. For language identification I use the analyzer command in the Linux console:

analyzer -f /usr/share/freeling/config/ident.cfg --outlv ident --fidn /usr/share/freeling/common/lang_ident/ident.dat

When I execute this command, its wait for the text entries (sentences) and determine what language they are in. When I write a line of text in Spanish: "la casa es azul" and I press the enter key returns ES which means that it is written in Spanish. If I write "the house is blue" it returns EN, for the English language. To interrupt its execution press <kbd>Ctrl</kbd> + <kbd>C</kbd>.

When I execute this command in the Linux console the first sentence takes some time to respond and the other times responds quickly.

I use this code to execute this php command but it takes many seconds to return the result:

<?php
$cmd = "analyzer -f /usr/share/freeling/config/ident.cfg --outlv ident --fidn /usr/share/freeling/common/lang_ident/ident.dat";

$descriptorspec = array(
    0 => array("pipe", "r"),
    1 => array("pipe", "w"),
    2 => array("pipe", "w"),
);

$process = proc_open($cmd, $descriptorspec, $pipes);

$oracion[0]="we are the word";
$oracion[1]="somos el mundo";

if (is_resource($process)) {

    fwrite($pipes[0], $oracion[0]);
    fwrite($pipes[0], $oracion[1]);
    fclose($pipes[0]);

    while($pdf_content = fgets($pipes[1]))
    {
    echo $pdf_content . "<br>";
    }
    fclose($pipes[1]);
    $return_value = proc_close($process);

}
?>

How can I improve the response time?

  • 写回答

1条回答 默认 最新

  • doubang9906 2018-06-13 09:25
    关注

    When you run the program, it needs to load the statistical models for all languages. That's why the first sentence takes longer.

    The "analyzer" program provided with FreeLing is just a demo. The best way to use the library is to write your own program, as shown in FreLing tutorial https://talp-upc.gitbooks.io/freeling-tutorial/content/

    If you want to call FreeLing from PHP, there is no API, so you should probably resort to "server mode", where freeling is loaded once, and then it will accept requests.

    You'll find more information in FreeLing user manual https://talp-upc.gitbooks.io/freeling-4-1-user-manual/content/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog