ExifTool PHP Fast Processing Script using StayOpen and Gearman

Started by TSM, November 05, 2013, 08:13:39 AM

Previous topic - Next topic

TSM

Thats just the defaults for the API and as it happens we store the JSON data directly in the DB instead of using PHP serialise/unserialize, we considered json to be more portable than PHP arrays, pros and conns for everything.
It does not cause any problem putting it in PHP mode in my script as if you use fetch() it does not try and decode it, passes it raw back to you to do as you please, if you use fetchDecoded() then it will require the output format to be json.
Why I did this I do not know, but works for us.
Im just altering our internal app so we move all exiftool writing over to use the API via Gearman instead of local, before we were only optimizing the reading.

klarakos

Hmmm, i think its all got slow once i moved to using fgets using a buffered socket, before i was using streams but found it incompatible with different version of php.
Ive checked and the PID does not change of the underlying perl once it has been started so its related to the fgets.
Ile look into it and get it sorted hopefully.

TSM

Quote from: klarakos on August 01, 2014, 05:52:49 AM
Hmmm, i think its all got slow once i moved to using fgets using a buffered socket, before i was using streams but found it incompatible with different version of php.
Ive checked and the PID does not change of the underlying perl once it has been started so its related to the fgets.
Ile look into it and get it sorted hopefully.

??

mauricio

I have written a simple php script to run exiftool, it works correctly but I am not sure if it is the best way to implement it, they could give me advice or give their point of view.
thank you in advance for your cooperation


<?php 
  $env 
null
  
$cwd "."
  
$descriptorspec = array ( 
  
=> array ( "pipe" "r" ),  
  
=> array ( "pipe" "w" ), 
  ); 
  
 
$command escapeshellcmd("exiftool -json imagenes/test3.jpg");
 
$process proc_open($command,$descriptorspec,$pipes,$cwd,$env); 

  if (
is_resource($process)) {
   
    
fwrite($pipes[0], "-stay_open\nFalse\n");
    
fclose($pipes[0]);

    echo 
stream_get_contents($pipes[1]);
    
fclose($pipes[1]);
    
    
proc_close($process);

}
?>


jaireaux

In case someone finds this forum post, as I did, seven years later, I was just looking for some good examples of using exiftool in PHP and came across this thread. I'm not working with a massive number of photos so I almost ignored it but tested it for just 10 pictures and the speed increase is dramatic. Here is the debug output I've used to time the difference between approaches.

using direct exec start time is 2020-03-13 11:04:14:773
using direct exec end time is 2020-03-13 11:04:16:900

using exif handler start time is 2020-03-13 11:04:16:900
using exif handler end time is 2020-03-13 11:04:17:495


So with this small test, using a 'shell_exec("exiftool...")' took  2,127milliseconds and using '$exif->..." took 595 milliseconds. That's almost a 75% improvement.

In summary, thanks to everyone who's kept this script alive. It's going to save me a lot of time, even with a smaller pool of images.

jlb30504

Please excuse the newby question.  I take it that EXifToolBatch.php does not work in the Apache environment since PCNTL doesn't work in Apache.  Is this correct?