dpzjl68484 2012-03-21 22:33
浏览 126
已采纳

无法通过PHP shell_exec运行sox命令

I've searched for help and tried everything on this thread, but still can't make this work. I'm trying to run the sox (Sound eXchange) command line utility from my PHP script using shell_exec(). I need to concatenate two audio files, both of which are in the same directory as the PHP script (i.e. accessible to apache).

Here's the confusion:

  1. Some sox commands work fine using shell_exec(). For example I can play an audio file or retrieve information about it.
  2. If I echo out the concatenation command (so I know exactly what PHP is sending to the shell) and then copy and paste it into a shell window, it runs perfectly.
  3. My apache user (_www) has full rights to the directory where the PHP script is, as well as the sox directory. I ran "chown -R _www:_www" and "chmod -R 777" on both directories.
  4. I'm using the full path to the sox executable and the audio files.

So this works in the shell:

"/soxpath/sox /filepath/file1.wav /filepath/file2.wav /filepath/combined.wav"

But this doesn't work from PHP:

shell_exec('/soxpath/sox /filepath/file1.wav /filepath/file2.wav /filepath/combined.wav');

Can anyone shed some light on this? What am I missing? Thanks.

  • 写回答

1条回答 默认 最新

  • dongyin2390 2012-03-28 22:56
    关注

    Okay, I got it working finally so I thought I should clear up any confusion I created. The problem was something unrelated. So, yes, you can run sox commands from PHP using shell_exec().

    I was simply running into a timing issue with javascript. I was using wami recorder to capture audio on the client side and then save the audio file on the server. So my PHP script was in the context of an ajax call handler, which by definition is asynchronous. Should have realized that earlier.

    The issue was that the file was not done saving when the sox command to concatenate was run, so naturally it failed because the file didn't exist yet. When I made the call synchronous it worked.

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

报告相同问题?

悬赏问题

  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址