exec() is not working - php

I am doing the conversion from youtube link to gif image ,but i faced some problem while executing exce() function.
echo $ret = exec("youtube-to-gif -u https://www.youtube.com/watch?v={$vidID} -b $start_second -d $different_second -s 480x? -o {$filePath}{$fileName} -f 10", $out, $err);
I am using exec() ,but its not returning any value .Here i am not getting why it is not working.
Thanks ,any suggestion will highly appreciate.

First, store your command in a variable and try echoing it and runnining in a terminal to see if it's valid at all:
$command = "youtube-to-gif -u https://www.youtube.com/watch?v={$vidID} -b $start_second -d $different_second -s 480x? -o {$filePath}{$fileName} -f 10";
echo $command . PHP_EOL;
echo $ret = exec($command, $out, $err) . PHP_EOL;
If it works fine when you run it manually, try full path to youtube-to-gif. Assuming you are running php on Linux, you should be able to do it with this command:
which youtube-to-gif
Now replace youtube-to-gif with the full path in $command.

Related

exec(ffmpeg) is not executing in php but will in terminal?

i have a website that allows users to upload videos and I have VPS server with ffmpeg installed, safe mode is off and have tested command in my terminal and it works however in php script when i try and run the command in exec() or even shell_exec() it does not execute. below is my code (changed some variables for privacy).
$video_name = $_FILES["post_vid"]["name"];
$Vurl = "/folder1/folder2/$vrand_file_name/$video_name";
$VnewName = $vrand_vid_name .".mp4";
$VurlNew = "/folder1/folder2/$vrand_file_name/$VnewName";
$convertold = "/home/user/directory/domain.com/$Vurl";
$convertNew = "/home/user/directory/domain.com/$VurlNew" ;
$ffmpegC = "/user/local/bin/ffmpeg";
exec($ffmpegC.' -y -i "'.$convertold.'" -f mp4 "'.$convertNew.'"');
I have the code just after a move_uploaded_file() which runs fine.
also checked and my php is using the same user as my terminal...
any insight to this would be fantastic, thanks in advance.
Please fix your code near exec as follows, and Could you try?
$command = $ffmpegC.' -y -i "'.$convertold.'" -f mp4 "'.$convertNew.'" 2>&1';
exec($command, $array);
var_dump($array);
exit;
By using 2>&1, stderror is entered to $array.
So you can see the cause.
Good luck!

Unoconv not creating pdf file in php script

When I run this phpscript in my mac xampp it return successful but not pdf file is generated. But when I run from mac terminal it able to create the pdf file from the docx file.
<?php
$source_file = 'c++ documentation.docx';
$cmd = "unoconv/0.7/bin/unoconv";
$command = sprintf("/Applications/XAMPP/xamppfiles/htdocs/phpdocx/unoconv/0.7/bin/unoconv -h -v -f pdf -o /phpdocx/docimages/testing.pdf %s 2>&1",
escapeshellarg($source_file));
echo shell_exec($command);
echo "yoyo";
if(shell_exec($command)){
echo "successful";
}else{
echo "failed";
}
?>
This is my edited code and it said sprintf(): Too few argument!
You need to escape the shell arguments, otherwise the shell may interpret its special characters:
$source_file = 'c++ documentation.docx';
$command = sprintf("unoconv/0.7/bin/unoconv -h -v -f pdf -o /phpdocx/docimages/testing.pdf %s 2>&1",
escapeshellarg($source_file));
Provide full (absolute) path to your unoconv/0.7/bin/unoconv executable, as it seems unavailable from your $PATH environment variable:
$command = sprintf("/path/to/unoconv/0.7/bin/unoconv -h -v -f pdf -o /phpdocx/docimages/testing.pdf %s 2>&1",
escapeshellarg($source_file));
Alternatively, include the absolute path to unoconv/0.7/bin/ directory into the $PATH environment variable before calling the shell. Refer to this post, for instance.
Obviously, the $source_file should be in the current directory. Otherwise, the command will fail to access it.

Php exec() function is not working on heroku with command nice

I am using the following lines of php code in my heroku php app, but these lines are not working :
$exec = "ps -p pid | grep pid.php";
$cmd='nice -n15 ' . php path . ' external.php ';
$cmd.=" > /dev/null 2>/dev/null & echo $!";
$out=array();
exec($cmd, $out);
Could you please suggest any other alternative of this or what mistake this code have?

Pass cmd commands via php script

Here is my php code
$command = "C:\Program Files\ClustalW2>clustalw2 -INFILE=seq.txt -TYPE=Protein -OUTFILE=res.aln";
exec($command);
When i run the command using the cmd, it generates the desired file. However when i try passing the same command via my php code it generates no result. How do i fix this problem?
Probably it's because of the > symbol before executable's filename? Also, try with single quotes:
$command = 'C:\Program Files\ClustalW2\clustalw2 -INFILE=seq.txt -TYPE=Protein -OUTFILE=res.aln';
exec($command, $output, $retval);
var_dump($output);
var_dump($retval);

Pass php variable to exec

I need to get dimm info using ipmitool as follows:
exec("/usr/bin/ipmitool -I lan -H $spip -U root -P '$thepassword' sunoem cli 'show System/Memory/DIMMs/$a' | grep -i location", $dimm_loc, $ipmiretval);
$a is previously defined as:
$a=$dimm[$i]
The return value for the above exec command is 1. If I replace $a with its vaule, i.e
exec("/usr/bin/ipmitool -I lan -H $spip -U root -P '$thepassword' sunoem cli 'show System/Memory/DIMMs/D5' | grep -i location", $dimm_loc, $ipmiretval);
The exec command executes as expected. So it looks like $a cannot be used in the above example. How else can I pass the variable to the exec command?
Thanks!!
Run var_dump($a) and see what actualy it contains. Also dump the executed command as a string to see if command is formated properly.
One more tip. Instead of doing an exec("some very long command line"), put your command line in a variable, then both LOG and exec() the variable. For example:
$fmt="/usr/bin/ipmitool -I lan -H %s -U root -P '%s' sunoem cli 'show System/Memory/DIMMs/%s' | grep -i location";
$cmd=sprintf($fmt, $spip, $thepassword, $a);
exec($cmd, $dimm_loc, $ipmiretval);
syslog(LOG_DEBUG, "Running: $cmd");
if ($ipmiretval > 0) {
syslog(LOG_ERR, "exec FAILED: $cmd");
} else {
syslog(LOG_DEBUG, "exec: $cmd");
}

Categories