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 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助