douying3251 2012-04-22 20:40
浏览 44
已采纳

PHP运行外部程序,Apache挂起

Basically my situation is as follows.

  1. Upload file
  2. Run external process on file (which generates another file)
  3. When external process is down, process the generated file.

Currently in PHP I run the program as follows:

$cmd = 'cd the_directory/; ./the_program'
system($cmd);

The program runs fine and everything, but the program at the end says "Press Enter to exit..." And thus Apache is hanging indefinitely as this program is waiting for user input. Our partner declares that they have this program integrated into their backend flawlessly and does not experience this issue. Up until now all external programs that i have executed in PHP exit without requiring user input which seems to be the norm for this situation.

It seems to me that the code should just simply not have the end message requiring user input. Am I missing something? Or is there a way to get around this? Or do they just need to change their code? Thanks!

  • 写回答

2条回答 默认 最新

  • dongxi7609 2012-04-22 20:45
    关注

    I think you should try proc_open.

    With it you can not only execute an external command as a process, but also set pipes to get and send information to that process.

    Take a close look to the third parameter of this function, and study the example in the PHP manual for this function, where you can see something like this:

    fwrite($pipes[0], '<?php print_r($_ENV); ?>');
    

    so, you can write what you need to the input pipe of the process you've just opened.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错