piwigo-videojs icon indicating copy to clipboard operation
piwigo-videojs copied to clipboard

PHP timeout on long video while creating thumbnails

Open xbgmsharp opened this issue 9 years ago • 4 comments

Thanks to @photonensammler for reporting this issue.

PHP timeout on long video while creating thumbnails.

http://php.net/manual/en/function.set-time-limit.php

The set_time_limit() function and the configuration directive max_execution_time only affect the execution time of the script itself. Any time spent on activity that happens outside the execution of the script such as system calls using system(), stream operations, database queries, etc. is not included when determining the maximum time that the script has been running. This is not true on Windows where the measured time is real.

Seen to be more a windows problem more than a Linux one.

This function has no effect when PHP is running in safe mode. There is no workaround other than turning off safe mode or changing the time limit in the php.ini.

Your web server can have other timeout configurations that may also interrupt PHP execution. Apache has a Timeout directive and IIS has a CGI timeout function. Both default to 300 seconds. See your web server documentation for specific details.

xbgmsharp avatar Mar 12 '15 11:03 xbgmsharp

I have been thinking about the issue. The best would be to do the timeout change only if need. It can be calculate by dividing the thumbnail request by the video length. However the sync function run in a loop for each video file in a selected album. There is no way to have the video length for each video without parsing the data first. As result the code will enable and disable the timeout multiple time which is not ideal.

One option is run each thumbnail is a separate process and not wait for the result. Another option is create a batch file and execute the batch file a separate process.

Also it seen to be more a Windows problem more than a Linux one.

xbgmsharp avatar Mar 13 '15 15:03 xbgmsharp

The generation of thumbnails is now very much faster! Now I can create the thumbnails with 1 second step for 4 long videos simultaneously (2384 Thumbnails) without php timeout with the same settings in which I have previously received a timeout error. You've done a good work!

xbgmsharp avatar Mar 14 '15 15:03 xbgmsharp

This issue is still valid is the video if the video length * by the thumbnails second exceed 300 seconds. Also it does only apply to Windows system.

xbgmsharp avatar Mar 16 '15 13:03 xbgmsharp

The max_execution_time in PHP for Windows is not set by default, because there is no php.ini. In the packages for download are the files php.ini-developement and php.ini-production ar available. In both files is the standard max_execution_time set to 30s (http://php.net/manual/en/info.configuration.php and http://windows.php.net/download/ , unpack the archive and see the php.ini-*). Without a php.ini you can set the maximum execution time with the function set_time_limit();. Here also the default limit is 30s (http://php.net/manual/en/function.set-time-limit.php). Therefore, I propose to change the max_execution_time in Windows always. Either at each iteration of the loop with function set_time_limit(); or before the start of the loop with ini_set ('max_execution_time', ...).

photonensammler avatar Mar 16 '15 16:03 photonensammler