Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php mysqldump problem 1

Status
Not open for further replies.

keesvanbreukelen

Programmer
Oct 28, 2002
8
NZ
Hi

I use mysqldump from php to backup my mysql database. The code to do the backup is:

exec('c:\wamp\bin\mysql\mysql5.1.33\bin/mysqldump -hlocalhost -uroot wbs_ezitime > c:\temp\test.sql');

When I run my php file, the backup file is produced correctly, but the script then hangs and never returns or times out. When I paste the command to a command line it works correctly.

Any suggestions how to fix or drill down would be appreciated.

Kees
 
What do you get when you use proc_open to call this shell command?

The exec command is a bit silent when it comes to error handling.

If you like you can use the following class:
Code:
<?php
// Execute a command, with monitoring of all streams.
// $Author: DonQuichote $
// $Date: 2010-02-12 10:45:58 +0100 (Fri, 12 Feb 2010) $
// $Revision: 1 $

class NonZeroCommandExitCodeException extends Exception
{public function __construct($strMessage, $intCode)
         {parent::__construct($strMessage, $intCode);}
} // class NonZeroCommandExitCodeException

class clsShellCommand
{private $mblnFailIfNonZeroExit;
 private $mintReturnCode = -1;
 private $mmixInputStream = NULL;
 private $mstrCommand;
 private $mstrErrorStream = '';
 private $mstrOutputStream = '';
 public function __construct($strCommand, $blnFailIfNonZeroExit=TRUE)
         {if(! is_string($strCommand)):
             throw new Exception('Command must be a string, not the ' . gettype($strCommand) . ' ' . var_export($strCommand, TRUE));
          endif;
          $this->mstrCommand = $strCommand;
          $this->mblnFailIfNonZeroExit = $blnFailIfNonZeroExit; }
 public function ErrorOutput()
         {return $this->mstrErrorStream;}
 public function Run()
         {$arrStreamSpec = array(0=>array('pipe', 'r'), 1=>array('pipe', 'w'), 2=>array('pipe', 'w'));
          $resProcess = proc_open($this->mstrCommand, $arrStreamSpec, $arrPipes);
          if(is_string($this->mmixInputStream)):
             fwrite($arrPipes[0], $this->mmixInputStream, strlen($this->mmixInputStream));
          endif;
          fclose($arrPipes[0]);
          $this->mstrOutputStream = stream_get_contents($arrPipes[1]);
          fclose($arrPipes[1]);
          $this->mstrErrorStream = stream_get_contents($arrPipes[2]);
          fclose($arrPipes[2]);
          $this->mintReturnCode = proc_close($resProcess);
          if($this->mblnFailIfNonZeroExit and ((strlen((string) $this->mstrErrorStream)>0) or ($this->mintReturnCode>0))):
             throw new NonZeroCommandExitCodeException('Script "' . $this->mstrCommand . '" ended with exit code ' . $this->mintReturnCode . '.', $this->mintReturnCode);
          endif; }
 public function SetInput($strContents)
         {$this->mmixInputStream = $strContents;}
 public function TextOutput()
         {return $this->mstrOutputStream;}
 public function ReturnCode()
         {return $this->mintReturnCode; }
} // class clsShellCommand
?>

+++ Despite being wrong in every important aspect, that is a very good analogy +++
Hex (in Darwin's Watch)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top