commit
				
					
						443939ba9a
					
				
			
		
					 3 changed files with 96 additions and 3 deletions
				
			
		|  | @ -82,6 +82,34 @@ Basic Usage | ||||||
|            ->extractImage(12, 'second-screenshot.jpg') |            ->extractImage(12, 'second-screenshot.jpg') | ||||||
|            ->close(); |            ->close(); | ||||||
| 
 | 
 | ||||||
|  | Process Timeout | ||||||
|  | --------------- | ||||||
|  | 
 | ||||||
|  | PHP-FFMpeg runs ffmpeg commands to processs your medias. A default timeout of | ||||||
|  | 60 seconds is set, but you can override this by passing a second argument load : | ||||||
|  | 
 | ||||||
|  | .. code-block:: php | ||||||
|  | 
 | ||||||
|  |     <?php | ||||||
|  |     $ffmpeg = FFMpeg::load($logger, 500); | ||||||
|  | 
 | ||||||
|  |     // 500 | ||||||
|  |     echo $ffmpeg->getTimeOut(); | ||||||
|  | 
 | ||||||
|  | You can also set and get the timeout with the appropriate getter and setter : | ||||||
|  | 
 | ||||||
|  | .. code-block:: php | ||||||
|  | 
 | ||||||
|  |     <?php | ||||||
|  |     $ffmpeg->setTimeout(200); | ||||||
|  | 
 | ||||||
|  |     // 200 | ||||||
|  |     echo $ffmpeg->getTimeOut(); | ||||||
|  | 
 | ||||||
|  | .. note:: | ||||||
|  | 
 | ||||||
|  |     To disable timeout, set its value to 0. | ||||||
|  | 
 | ||||||
| Recipes | Recipes | ||||||
| ------- | ------- | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -12,6 +12,7 @@ | ||||||
| namespace FFMpeg; | namespace FFMpeg; | ||||||
| 
 | 
 | ||||||
| use FFMpeg\Exception\BinaryNotFoundException; | use FFMpeg\Exception\BinaryNotFoundException; | ||||||
|  | use FFMpeg\Exception\InvalidArgumentException; | ||||||
| use Monolog\Logger; | use Monolog\Logger; | ||||||
| use Symfony\Component\Process\ExecutableFinder; | use Symfony\Component\Process\ExecutableFinder; | ||||||
| 
 | 
 | ||||||
|  | @ -40,7 +41,7 @@ abstract class Binary implements AdapterInterface | ||||||
|      * |      * | ||||||
|      * @param type   $binary The path file to the binary |      * @param type   $binary The path file to the binary | ||||||
|      * @param Logger $logger A logger |      * @param Logger $logger A logger | ||||||
|      * @param Integer $timeout The timout for the underlying process |      * @param Integer $timeout The timout for the underlying process, 0 means no timeout | ||||||
|      */ |      */ | ||||||
|     public function __construct($binary, Logger $logger, $timeout = 60) |     public function __construct($binary, Logger $logger, $timeout = 60) | ||||||
|     { |     { | ||||||
|  | @ -50,7 +51,35 @@ abstract class Binary implements AdapterInterface | ||||||
| 
 | 
 | ||||||
|         $this->binary = $binary; |         $this->binary = $binary; | ||||||
|         $this->logger = $logger; |         $this->logger = $logger; | ||||||
|  |         $this->setTimeout($timeout); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Returns the current timeout for underlying processes. | ||||||
|  |      * | ||||||
|  |      * @return integer|float | ||||||
|  |      */ | ||||||
|  |     public function getTimeout() | ||||||
|  |     { | ||||||
|  |         return $this->timeout; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Sets the timeout for the underlying processes, use 0 to disable timeout. | ||||||
|  |      * | ||||||
|  |      * @param integer|float $timeout | ||||||
|  |      * | ||||||
|  |      * @return Binary | ||||||
|  |      */ | ||||||
|  |     public function setTimeout($timeout) | ||||||
|  |     { | ||||||
|  |         if (0 > $timeout) { | ||||||
|  |             throw new InvalidArgumentException('Timeout must be a positive value'); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         $this->timeout = $timeout; |         $this->timeout = $timeout; | ||||||
|  | 
 | ||||||
|  |         return $this; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  | @ -65,11 +94,13 @@ abstract class Binary implements AdapterInterface | ||||||
|      * {@inheritdoc} |      * {@inheritdoc} | ||||||
|      * |      * | ||||||
|      * @param  Logger $logger A logger |      * @param  Logger $logger A logger | ||||||
|  |      * @param  Integer $timeout The timout for the underlying process, 0 means no timeout | ||||||
|  |      * | ||||||
|      * @return Binary The binary |      * @return Binary The binary | ||||||
|      * |      * | ||||||
|      * @throws Exception\BinaryNotFoundException |      * @throws Exception\BinaryNotFoundException | ||||||
|      */ |      */ | ||||||
|     public static function load(Logger $logger) |     public static function load(Logger $logger, $timeout = 60) | ||||||
|     { |     { | ||||||
|         $finder = new ExecutableFinder(); |         $finder = new ExecutableFinder(); | ||||||
|         $binary = null; |         $binary = null; | ||||||
|  | @ -84,7 +115,7 @@ abstract class Binary implements AdapterInterface | ||||||
|             throw new BinaryNotFoundException('Binary not found'); |             throw new BinaryNotFoundException('Binary not found'); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         return new static($binary, $logger); |         return new static($binary, $logger, $timeout); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  |  | ||||||
|  | @ -29,6 +29,40 @@ class BinaryTest extends \PHPUnit_Framework_TestCase | ||||||
|         $binary = new BinaryTester('pretty_binary', $this->logger); |         $binary = new BinaryTester('pretty_binary', $this->logger); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     public function testTimeout() | ||||||
|  |     { | ||||||
|  |         $tester = BinaryTester::load($this->logger, 200); | ||||||
|  |         $this->assertEquals(200, $tester->getTimeout()); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public function testDefaultTimeout() | ||||||
|  |     { | ||||||
|  |         $tester = BinaryTester::load($this->logger); | ||||||
|  |         $this->assertEquals(60, $tester->getTimeout()); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public function testNoTimeout() | ||||||
|  |     { | ||||||
|  |         $tester = BinaryTester::load($this->logger, 0); | ||||||
|  |         $this->assertEquals(0, $tester->getTimeout()); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public function testSetTimeout() | ||||||
|  |     { | ||||||
|  |         $tester = BinaryTester::load($this->logger); | ||||||
|  |         $tester->setTimeout(200); | ||||||
|  |         $this->assertEquals(200, $tester->getTimeout()); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * @expectedException \FFMpeg\Exception\InvalidArgumentException | ||||||
|  |      */ | ||||||
|  |     public function testSetInvalidTimeout() | ||||||
|  |     { | ||||||
|  |         $tester = BinaryTester::load($this->logger); | ||||||
|  |         $tester->setTimeout(-1); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     /** |     /** | ||||||
|      * @covers FFMpeg\Binary::load |      * @covers FFMpeg\Binary::load | ||||||
|      */ |      */ | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue