من یه اسکریپ نوشتم که از یه سایت لینک دانلود رو میگیره و اونو ذخیره میکنه و از ffmpeg هم استفاده میکنم و کدم به شکل زیر هست و وقتی روی کرون جاب تنظیمش میکنم مصرف cpu 100درصد میشه و فایل error log اپاچم کاملا پر میشه و حجم سرور را اشغال میکنه کاملا چه راه حلی براش دارین>؟
<head>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head><?php
$con=mysql_connect('secret');
mysql_query("SET NAMES 'utf8'", $con);
mysql_query("SET CHARACTER SET 'utf8'", $con);
mysql_query("SET character_set_connection = 'utf8'", $con);
mysql_select_db('secret');
if (!$con){
die("no connect to db <br />" . mysql_error());
}
$dbb=mysql_query("SELECT * FROM secret WHERE numberl='0' ",$con);
$mcc=mysql_fetch_assoc($dbb);
echo $mcc["idl"];
$idd = $mcc["idl"];
$dbresult=mysql_query("SELECT * FROM secretsecretv WHERE id=$idd ",$con);
$amch=mysql_fetch_assoc($dbresult);
echo $amch["url"];
mysql_close($con);
echo $id;
$url = $amch["url"];
$cat = $amch["cat"];
echo $url ;
?>
<?php
$idplus = $idd + 1 ;
$con=mysqli_connect(secretsecret);
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysqli_query($con,"UPDATE secretsecret SET index='1' WHERE id=$idd ");
mysqli_query($con,"UPDATE secretsecret SET idl=$idplus WHERE numberl='0' ");
mysqli_close($con);
?>
<?php
$html = file_get_contents ($url);
preg_match('/<meta property="og:video:url" content="(.*?)">/', $html, $matches);
if (isset($matches[1]))
{
$video['url'] = $matches[1];
$filename=explode('/', $matches[1]);
$video['name'] = end($filename);
}
unset($matches);
preg_match('/<meta property="og:title" content="(.*?)" \/>/', $html, $matches);
if (isset($matches[1]))
{
$video['title'] = $matches[1];
}
unset($matches);
preg_match('/<meta property="og:description" content="(.*?)" \/>/', $html, $matches);
if (isset($matches[1]))
{
$video['description'] = $matches[1];
}
preg_match('/<meta property="og:title" content="(.*?)" \/>/', $html, $matches);
if (isset($matches[1]))
{
$pieces=explode(' ', $matches[1]);
$video["tags"] = implode(",", $pieces).','. $matches[1];
}
echo $video['url'];
echo $video['title'];
echo $video['description'];
echo $video['tags'];
$descriptionv = $video['description'];
$tags = $video['tags'];
$titlev = $video['title'];
$url = $video['url'];
define('BUFSIZ', 1092);
$rfile = fopen($url, 'r');
$lfile = fopen(basename($vidname), 'wb');
while(!feof($rfile))
fwrite($lfile, fread($rfile, BUFSIZ), BUFSIZ);
fclose($rfile);
fclose($lfile);
echo '<br>';
echo $vidname;
echo $video['name'];
$ffmpeg = '/usr/bin/ffmpeg';
//video dir
$video = $video['name'];
$uuu=explode('-', $video);
$ttt=explode('_', $uuu[1]);
$bbb=$ttt[0];
$digits = preg_replace("/[^0-9]/", '', $bbb);
if ($digits<360)
{
$ext='240' ;
}
elseif ($digits<480)
{
$ext='360' ;
}
elseif ($digits<720)
{
$ext='480' ;
}
elseif ($digits<1080)
{
$ext='720' ;
}
elseif ($digits<1440)
{
$ext='1080' ;
}
elseif ($digits<2160)
{
$ext='1440' ;
}
elseif ($digits<3000)
{
$ext='2160' ;
}
else {
$ext='240' ;
}
echo '<br>';
echo $ext;
echo '<br>';
//where to save the image
$namev = rand(100,999).uniqid(8).uniqid(14);
echo '<br>';
echo $image ;
//time to take screenshot at
$interval = 5;
//screenshot size
$size = '320x240';
//ffmpeg command
$cmd = "$ffmpeg -i $video -deinterlace -an -ss $interval -f mjpeg -t 1 -r 1 -y -s $size $namev'.jpg' 2>&1";
$return = `$cmd`;
ob_start();
passthru("ffmpeg -i $video 2>&1");
$duration = ob_get_contents();
ob_end_clean();
preg_match('/Duration: (.*?),/', $duration, $matches);
$duration = $matches[1];
list($hr,$m,$s) = explode(':', $duration);
$duration_in_seconds = ( (int)$hr*3600 ) + ( (int)$m*60 ) + (int)$s;
echo '<br>';
echo $duration_in_seconds;
$file = $namev.'.jpg';
$dest = 'thumbs/'.$namev.'.jpg';
copy($file, $dest);
unlink($file);
$user = rand(1,100);
$liked = rand(1,300);
$disliked = rand(1,80);
$views = rand(300,800);
$videothumb = 'http://s2.maxtoop.com/media/thumbs/'.$namev.'.jpg';
$con=mysql_connect('secret');
mysql_query("SET NAMES 'utf8'", $con);
mysql_query("SET CHARACTER SET 'utf8'", $con);
mysql_query("SET character_set_connection = 'utf8'", $con);
mysql_select_db('secret');
if (!$con){
die("no connect to db <br />" . mysql_error());
}
$sql="INSERT INTO secretsecretsecret (`date`,`media`,`token`,`pub`, `user_id`, `source`, `title`, `thumb`,`duration`,`description`, `tags`, `category`, `views`, `liked`, `disliked`, `server`, `size`) VALUES (now(),'1','".$namev."','1','".$user."','up','".$titlev."','".$videothumb."','".$duration_in_seconds."','".$descriptionv."','".$tags."','".$cat."','".$views."','".$liked."','".$disliked."','s2','".$ext."')";
if (!mysql_query($sql,$con)){
die('error:' . mysql_error());
}else{
echo "seved";
}
mysql_close($con);
// a work around for now - need to remove when above works
//$duration_in_seconds = 10800
//}?>
<?php
$conn=mysql_connect('secretsecret');
mysql_query("SET NAMES 'utf8'", $conn);
mysql_query("SET CHARACTER SET 'utf8'", $conn);
mysql_query("SET character_set_connection = 'utf8'", $conn);
mysql_select_db('secret');
if (!$conn){
die("no connect to db <br />" . mysql_error());
}
$sql="INSERT INTO aparat (`url`,`token`) VALUES ('".$video."','".$namev."')";
if (!mysql_query($sql,$conn)){
die('error:' . mysql_error());
}else{
echo "seved";
}
mysql_close($conn);
?>