Permalink
Browse files

Update server for Meta Reading

  • Loading branch information...
1 parent ff649af commit 9a070edc2f65bfa786d5b1779971477c775e47cb @romainneutron committed Aug 31, 2012
Showing with 12 additions and 17 deletions.
  1. +12 −16 lib/PHPExiftool/ExiftoolServer.php
  2. +0 −1 tests/lib/PHPExiftool/Test/Server/ReaderTest.php
@@ -57,7 +57,7 @@ public function isRunning()
public function executeCommand($commands, $timeout = 4)
{
- $optwithargs = array('-ext', '--ext', '-i', '-charset', '-if', '-w', '-common_args');
+ $optwithargs = array('-i', '-charset', '-if', '-w', '-common_args');
if (true !== $this->isRunning()) {
throw new RuntimeException('Server is not running');
}
@@ -83,40 +83,36 @@ public function executeCommand($commands, $timeout = 4)
if ($command == '-q') {
continue;
}
- if (in_array($prev, $optwithargs)) {
- $command = trim($command, "'\"");
- }
- if (in_array($command, $optwithargs)) {
- $end = ' ';
- $prev = $command;
- } else {
- $end = "\n";
- $prev = null;
+ if (substr($command, 0, 1) === "'" && substr($command, -1) === "'") {
+ $command = substr($command, 1, -1);
}
-
- if (file_exists(trim($command, "'"))) {
- $command = trim($command, "'");
+ if (substr($command, 0, 1) === '"' && substr($command, -1) === '"') {
+ $command = substr($command, 1, -1);
}
+ $end = "\n";
+
// echo $command . $end;
file_put_contents($this->pipefile, $command . $end, FILE_APPEND);
}
file_put_contents($this->pipefile, "\n-execute\n", FILE_APPEND);
-// echo "-execute\n";
+// echo "-execute\n\n";
// here we send sigcont
$start = microtime(true);
- while (strlen($this->server->getOutput()) <= $this->offset && substr(substr($this->server->getOutput(), $this->offset), -8) !== "{ready}\n" && (microtime(true) - $start) < $timeout) {
+ while ((strlen($this->server->getOutput()) <= $this->offset || substr(substr($this->server->getOutput(), $this->offset), -8) !== "{ready}\n") && (microtime(true) - $start) < $timeout) {
usleep(10000);
}
+ // server output should be cached here because streams are polled
+ // everytime I request the output
$outputIsValid = substr($this->server->getOutput(), -8) === "{ready}\n";
$output = $outputIsValid ? substr($this->server->getOutput(), $this->offset, -8) : '';
- $this->offset += strlen($this->server->getOutput());
+ $this->offset = strlen($this->server->getOutput());
if (trim($output) === '' && $outputIsValid === false && $this->server->getErrorOutput()) {
throw new RuntimeException('Command failed');
@@ -15,7 +15,6 @@ class ReaderTest extends AbstractReaderTest
protected function setUp()
{
- $this->markTestSkipped('Currently disable server support');
$this->exiftool = new ExiftoolServer();
$this->exiftool->start();

0 comments on commit 9a070ed

Please sign in to comment.