icon Get the most out of Surmunity, read our tips here! Need an interesting blog to read? You've got to read the Surpass Blog! | Welcome! Please register to access all of our features.

» Surpass Web Hosting Forums » Discussions » PHP, MySQL » Executing Shell from PHP Problem

PHP, MySQL General PHP questions. Or go to our PHPsuexec Forum >>

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread
Old February 5th, 2008, 3:12 PM   #1 (permalink)
Registered User
Fresh Surpasser
 
Joined in Aug 2007
15 posts
Gave thanks: 0
Thanked 0 times
Executing Shell from PHP Problem

I recently installed FFMpeg on my server, so I could make my script upload videos, then convert them to formats I want, like MP4 and FLV.
When I upload the file, I then call a function below:
PHP Code:
// Handle Video Uploads //
function videoHandle($_FILES$dir$number){
 if (!
file_exists($_SERVER['DOCUMENT_ROOT'].$dir))
  
mkdir($_SERVER['DOCUMENT_ROOT'].$dir0777);
  
  
$target_path $dir $number;
  
$cmd "ffmpeg -i ".$_FILES['upload']['tmp_name']." -y -sameq -f mp4 ".$_SERVER['DOCUMENT_ROOT'].$target_path.".mp4";
  
$output runExternal($cmd, &$code);
  if(
$code) echo "Bad Transcoding: <br/><br/>".$cmd."<br/><br/>".$output."<br/><br/>";
  else echo 
"<br/>Successfully Converted to MP4<br/>";
  
  
$cmd "ffmpeg -i ".$_FILES['upload']['tmp_name']." -y -sameq -f flv ".$_SERVER['DOCUMENT_ROOT'].$target_path.".flv";
  
$output runExternal($cmd, &$code);
  if(
$code) echo "Bad Transcoding: <br/><br/>".$cmd."<br/><br/>".$output."<br/><br/>";
  else echo 
"Successfully Converted to FLV<br/>";

The FFMpeg commands work fine, I've ran them in SSH, but when I call the script, I get:
Quote:
505 Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmasterdevelopment.psbeyond.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Checking the error log, the entry says:
Quote:
[05-Feb-2008 13:23:09] PHP Warning: stream_select() [<a href='function.stream-select'>function.stream-select</a>]: unable to select [4]: Interrupted system call (max_fd=10) in /home/cmsdev/public_html/admin/includes/functions.php on line 190
It's referring to my function "runExternal" which I got from the php site:
PHP Code:
// Run Linux Command Line //
function runExternal($cmd, &$code) {
   
$descriptorspec = array(
       
=> array("pipe""r"),  // stdin is a pipe that the child will read from
       
=> array("pipe""w"),  // stdout is a pipe that the child will write to
       
=> array("pipe""w"// stderr is a file to write to
   
);
   
$pipes= array();
   
$process proc_open($cmd$descriptorspec$pipes);
   
$output"";
   if (!
is_resource($process)) return false;
   
#close child's input imidiately
   
fclose($pipes[0]);
   
stream_set_blocking($pipes[1],false);
   
stream_set_blocking($pipes[2],false);
   
$todo= array($pipes[1],$pipes[2]);
   while( 
true ) {
       
$read= array();
       if( !
feof($pipes[1]) ) $read[]= $pipes[1];
       if( !
feof($pipes[2]) ) $read[]= $pipes[2];
       if (!
$read) break;
       
$readystream_select($read$write=NULL$exNULL2);
       if (
$ready === false) {
           break; 
#should never happen - something died
       
}
       foreach (
$read as $r) {
           
$sfread($r,1024);
           
$output.= $s;
       }
   }
   
fclose($pipes[1]);
   
fclose($pipes[2]);
   
$code proc_close($process);
   return 
$output;

I assume its breaking at the "stream_select" part. I've tried doing it without this function, with just shell_exec, but I encounter the same problem. However it looks like it might be some kind of timeout, or overload of information, because if I just convert the FLV, it seems to work fine. Any ideas as to how to prevent this? I've tried upping the max_execution_time in my php.ini file already, but that didn't fix the problem

I noticed that the files are actually being created successfully, but the rest of the script does not execute (I have some mysql queries that come afterwards that don't execute)

I also just noticed through testing, that the files are still being created even after the Server Error is giving, meaning the commands are being executed in the background after the error.

However, it looks like if the error happens while the first file is still being made, the second command is not executed (and the second file is not created). So it depends on when the crash happens....

Last edited by Roth; February 5th, 2008 at 3:13 PM..
Roth is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On