简体   繁体   中英

How to execute command-line utilities in PHP?

I have very limited knowledge when it comes to console commands. What I'm trying to achieve is to execute a console command within a PHP query.

Example

<?php 

   $sql = mysql_query("SELECT * FROM `users`");
   while( $select_users = mysql_fetch_array( $sql )){

   } 

?>

The command I want to execute within the WHILE

So within this query I want to execute this command however am unsure how to achieve this; I have looked at similar questions however unsure how to implement them into my example.

ffmpeg -ss 00:00:01.01 -i /my_video_file_dir/video.flv -y -f image2 \
   -vcodec mjpeg -vframes 1 /image_dir/screenshot.jpg

You can use exec function of php like this

$command = 'ffmpeg -ss 00:00:01.01 -i /my_video_file_dir/video.flv -y -f image2 -vcodec mjpeg -vframes 1 /image_dir/screenshot.jpg';

exec($command);

In additional to exec you can use from following command:

$output = shell_exec($command);

This command execute command via shell and return the complete output as a string, more information: http://php.net/manual/en/function.shell-exec.php

I had same requirement like you and used from this command

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM