I'm working on a page that does the following
uses youtube-dl to download a youtube video
then uses ffmpeg to transcode it into mp4
All works fine.
But after I want to send an email. Which I have right now working fine. Using PHP Mailer and all good..
But. the problem is when it goes to my generating page. It will send the email right away while it's doing the other stuff. So by the time it gets to people it might still be transcoding the file via ffmpeg. I just want to delay the email by say 60 seconds so the file can be done transcoding by the time it sends the email
Thoughts?
Here is my current code
<?
require('./site/user/session.php');
?>
<?
require("/usr/share/php/libphp-phpmailer/class.phpmailer.php");
include('./site/scripts/connection.php');
$receiver_name=$_POST["receiver_name"];
$receiver_email=$_POST["receiver_email"];
$mockup_name=$_POST["mockup_name"];
$layout_select=$_POST["layout_select"];
$comments=$_POST["comments"];
$sender=$_POST["sender"];
$sender_email=$_POST["sender_email"];
$youtube_url = $_POST['youtube_url'];
$filename = $_POST['filename'];
$date = date("Y-m-d");
$video_file = "http://example.com/video/$filename.mp4";
mysqli_query("INSERT INTO mockup VALUES ('', '$receiver_name', '$receiver_email', '$layout_select', '$video_file', '$date', '$sender')");
$video_id = mysqli_insert_id();
define('youtube-dl', '/usr/bin/youtube-dl');
define('FFMPEG', '/usr/bin/ffmpeg');
exec("youtube-dl -o $filename.tmp $youtube_url");
shell_exec("ffmpeg -y -i $filename.tmp -vcodec libx264 -b 1000k $filename.mp4 >/dev/null 2>/dev/null &");
sleep(30); // I'd like to have a delay right here
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "localhost";
$mail->SMTPAuth = false;
$mail->AddReplyTo("$sender_email", "$sender");
$mail->From = "$sender_email";
$mail->FromName = "$sender";
$mail->IsHTML(true);
$mail->Subject = "$mockup_name";
$mail->Body =
"<!DOCTYPE html>
<head>
</head>
<body>
Dear $receiver_name,<br><br>
Please see the link below to see what your ad would look like in our screens<br><br><br>
<a href='http://example.com/$layout_select.php?video=$video_id'>View your ad here</a><br><br>
Thanks,<br>
Staff
</body>
</html>";
$mail->AddAddress("$receiver_email");
$mail->Send();
?>
Any suggestions that I should do?