我正在开发一个网站,该网站将从远程URL获取MP3详细信息。我需要编写一个定时任务,以便获取所有歌曲信息,例如文件名、路径、艺术家、流派、比特率、播放时间等,并将其放入数据库表中。
我尝试使用getid3包,但当同时获取多个URL时,速度非常慢,而且会出现最大执行错误。
示例:
require_once('getid/getid3/getid3.php');
$urls = array ('http://stackoverflow.com/test1.mp3','http://stackoverflow.com/test2.mp3''http://stackoverflow.com/test3.mp3');
foreach($urls as $ur){
$mp3_det = getMp3Info( $ur );
print_r ($mp3_det);
}
function getMp3Info ( $url ){
if($url){
/**********/
$filename = tempnam('/tmp','getid3');
if (file_put_contents($filename, file_get_contents($url, false, null, 0, 35000))) {
if (require_once('getid/getid3/getid3.php')) {
$getID3 = new getID3;
$ThisFileInfo = $getID3->analyze($filename);
unlink($filename);
$bitratez = $ThisFileInfo[audio][bitrate] ? $ThisFileInfo[audio][bitrate] : '';
$headers = get_headers($url, 1);
if ((!array_key_exists("Content-Length", $headers))) { return false; }
// print $headers["Content-Length"];
$filesize= round($headers["Content-Length"]/1000);
$contentLengthKBITS=$filesize*8;
if ( $bitratez ){
$bitrate= round ( $bitratez/1000 );
$seconds=$contentLengthKBITS/$bitrate;
$playtime_mins = floor($seconds/60);
$playtime_secs = $seconds % 60;
if(strlen($playtime_secs)=='1'){$zero='0';}
$playtime_secs = $zero.$playtime_secs;
$playtime_string=$playtime_mins.':'.$playtime_secs;
}
else $playtime_string='0:00';
// echo '<pre>'.print_r($ThisFileInfo, true).'</pre>';
}
$bitrate = $bitrate ? $bitrate : 0;
$ret = array();
$ret['playtime'] = $playtime_string;
$ret['filesize'] = $filesize;
$ret['bitrate'] = $bitrate;
return $ret;
}
}
max_execution_time
参数吗?我认为改变它或将整个任务分成多个作业是唯一的解决方法。 - Pekka