CPG lags (sometimes times out with fatal error) when opening page w/ large video CPG lags (sometimes times out with fatal error) when opening page w/ large video
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

CPG lags (sometimes times out with fatal error) when opening page w/ large video

Started by stimpy2k, October 29, 2012, 03:42:49 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

stimpy2k

Hello all.

I'm experiencing an issue when using large videos with CPG. When you click on the item in the album, it takes a very long time for the page to load. Sometimes the page doesn't load at all, and ends up in a fatal error (see below). If the page does finally load (~25 seconds later), the video plays fine. It's just getting the page to load initially that seems to be the hang up. Other media on the site loads very quickly, it's just the large videos the cause the page load lag issue. These are very large videos we're talking about (several gigs). These are long 60fps full HD resolution files. Their file sizes can get quite large (5-10gb).

If the page loading times out, these are the two messages I have received...

Fatal error: Maximum execution time of 30 seconds exceeded in /home/********/themes/curve_dark/theme.php on line 292
-and-
Fatal error: Maximum execution time of 30 seconds exceeded in /home/********/include/functions.inc.php on line 5490

For theme.php, the line it gets stuck on (292) is...
if ($width == '-1') $width = $CONFIG['picture_table_width']

For functions.inc.php, the line it gets stuck on (5490) is...
$size = getimagesize($image);

Now, I'm no developer, and I hardly read PHP, but it looks to me like both of these lines are related to trying to determine image dimensions. Looks to me like CPG is trying to churn through the file to determine its dimensions, but since these file sizes are so large, I'm guessing it's taking the server a large amount of time to churn through the file. I suspect it is likely unable to determine the resolution anyway, since it is not actually an image file (maybe I'm wrong?). If this is the case, it seems it would be helpful for CPG to detect if the file extension is one associated with a video, and if so to bypass the process of trying to determine its dimensions.   ...then again, maybe I'm way off course and it's something completely different. I differ to the experts on this one.

I've setup an example of my issue here: http://www.pictureshome.com/thumbnails.php?album=1
This is a fresh install of CPG, with only two files in an album. One is an image, the other a large video. You will see the significant performance difference between loading the two pages, and occasionally (I suspect based on server load at the time) you will get a fatal error, timing out after 30 seconds.

Thank you all for your time. I appreciate your help.
-= Brandon.


Αndré

if ($width == '-1') $width = $CONFIG['picture_table_width'];
compares just two numbers. That was maybe random that the execution time exceeded exactly there.


$size = getimagesize($image);
not sure if there are known issues for that PHP function on large files (your example file is 2GiB). I'll check that as soon as possible in my testbed with such large files.

Αndré

My test results:


File sizePage load time
1 KB~ 0,1 s
10 MB~ 1 s
20 MB~ 3 s
30 MB~ 6 s
40 MB~ 10 s
50 MB~ 15 s

As you can see the file size significantly affects the page load time. I was able to find three resource hogs:

  • cpg_getimagesize in include/functions.inc.php (inside the function theme_html_picture)
  • exif_parse_file in displayimage.php (which itself contains cpg_getimagesize)
  • get_IPTC in displayimage.php (which contains GetImageSize)


Using
cpg_getimagesize(true)
at all occurrences fixes the issue for me, as it doesn't use PHP's getimagesize function but a custom one. Unfortunately the IPTC data isn't read with that custom function, but maybe there's a different way than getimagesize.


Partly related question: do we really need to use getimagesize and look for EXIF/IPTC data for non-image files? I currently don't know which file formats support EXIF and/or IPTC.

Αndré


stimpy2k

Thank you so much for working on this issue.

Unfortunately, it seems there's a snag. When you click on an item (either picture or video), it just goes to a blank page. After I enabled Debug Mode, instead of going to a blank page I got the following...

Fatal error: Call to undefined function cpg_picture_dimension_exceeds_intermediate_limit() in /home/********/include/themes.inc.php on line 3275

Thank you again for looking into this issue.
-= Brandon.

Αndré


stimpy2k

Oh, sorry about that.

I have modified the lines, rather than just copying the changed files over, and pages are loading properly again. Unfortunately, the lag is still happening with the video page.

You can see it with the altered files at: http://www.pictureshome.com/thumbnails.php?album=1

-= Brandon.

stimpy2k

If it helps, here are the modified files I made. Did I make a mistake somewhere in the modifications perhaps?

-= Brandon.

Αndré

Please review include/themes.inc.php, you moved the line to a wrong location.