【发布时间】:2011-07-22 18:42:02
【问题描述】:
好的,我有一个ENDLESS LOOP 我需要那个无限循环没有错!当我通过php script.php 启动该脚本时,它没有问题,但在第二个第三个等等......运行它不再正常工作。我在第二次运行时将 $output 作为测试添加到数据库中以查看有什么问题,并且我收到此错误a:1:{i:0;s:24:"sh: 0: command not found";} 其序列化。
请记住脚本在第一次运行时有效,但在第 2 次以上运行时从未运行,在第 3 次以上运行时 $output 和 $video 出现问题,
编码在每次运行时都有效,文件也被正确重命名,并正确移动
我试图在脚本末尾取消设置 $output $video $duration 和 $error,但我得到一个错误,变量未在第二次以上运行时定义。有什么想法有什么问题吗?
关于代码:我放了一个 sn-p 不是完整的代码,如果那里有错别字,它只是复制粘贴错误。
我的想法是 exec 是错误的,当他们在第二次运行时将输出提供给变量
这是我的脚本
<?php
while(10) {
// Getting Data From DB
$sql = "SELECT * FROM videos_to_edit WHERE status = 'pending' ORDER BY post_time ASC LIMIT 1";
// Encoding Video;
exec("$mencoder $temp_upload_dir$post_filename -o $temp_upload_dir$r_post_id.mp4 2>&1", $output);
// Checking if Mencoder could encode it
foreach($output as $error) {
if(preg_match('/============ Sorry, this file format is not recognized\/supported =============/', $error)) {
$error1 = "error";
}
}
if(!isset($error1)) {
// Getting duration of Video with mplayer
exec("$mplayer $temp_upload_dir$r_post_id.mp4 2>&1", $video);
// Getting the duration with preg_match
foreach($video as $vidlenght) {
if(preg_match('/ID_LENGTH=/', $vidlenght)) {
$duration = $vidlenght;
$duration = explode("=",$duration);
$duration = $duration['1'];
}
}
// MOVING FILE TO PUBLIC DIR
CODE HERE...
//UPDATING DB
$sql = "UPDATE videos_to_edit SET status = 'finished' WHERE post_id = ?";
}
}
?>
【问题讨论】:
-
你为什么使用
while(10)?该条件始终为真。 -
因为我想要一个无限循环,请阅读上面的文字
标签: php loops foreach exec infinite-loop