Hi, Recently i updated php version to 5.4 suddenly i have notices server getting overloaded, while checking error_log file its reporting the issue related to the following php code: <?php $imagesize = getimagesize($img_src); if($imagesize['0'] > 210): ?> I am not good at PHP, can anybody please help me adjusting the above code to work fine with the new version of PHP?
Can you provide the error? The code also seems to be incomplete / wrong. The snipped you provided will always throw a Parse error: syntax error, unexpected end of file
Hi, The complete coding and error messages are: <?php $image = get_post_meta(get_the_ID(), 'image_url', TRUE); ?> <?php $cat = ''; if(in_category('Themes')){$cat = 'themes/';} elseif(in_category('Apps')){$cat = 'apps/';} ?> <?php $img_src = get_bloginfo('url') . '/wp-content/uploads/' . $cat . $image; ?> <?php define('TIMBTHUMB', '/includes/timthumb.php?src='); ?> <?php if(!empty($image)): ?> <?php $imagesize = getimagesize($img_src); if($imagesize['0'] > 210): ?> PHP: and error_log reflects the following: [09-Aug-2013 11:09:16 UTC] PHP Warning: getimagesize(http://site.com/wp-content/uploads/themes/Scratched Screen.jpg) [<a href='function.getimagesize'>function.getimagesize</a>]: failed to open stream: HTTP request failed! in /home/site/public_html/wp-content/themes/mytheme/includes/single/default.php on line 34 Code (markup): Line 34 has the following coding (already pasted above but let me do it again) <?php $imagesize = getimagesize($img_src); if($imagesize['0'] > 210): ?> PHP: The server is getting overloaded and getting down from the last 12 hours, I am unable to understand how to fix.
Mhhh... seems like either the $img_src has a wrong path, or that getimagesize() can't access the path (insufficient permissions). Check the path and/or set folder permissions temporary to 777, and look if the error still persists. Alternatively, you can disable php error logging for that script with ini_set("log_errors", 0);
The 'real' fix should be to do a is_file($img_src) before you try to access it with getimagesize. While your little snippet doesn't give the whole picture, I get the feeling from things like the endless pointless opening and closing of PHP for no good reason on every blasted line is indicative of deep rooted problems with your entire codebase. Of course since this is obviously some code inside turdpress, that kind-of goes without saying. That 'empty' on $image should probably be checked FIRST, and where that check is testing is_file($img_src) should be placed instead. I'd actually need to see a lot more of the code to weigh in on how it should be handled, but: <?php if (!empty($image = get_post_meta(get_the_ID(), 'image_url', TRUE)) { $cat = ( in_category('Themes') ? 'themes/' : ( in_category('Apps') ? 'apps/' : '' ) ); $img_src = get_bloginfo('url') . '/wp-content/uploads/' . $cat . $image; define('TIMBTHUMB', '/includes/timthumb.php?src='); if (is_file($img_src)) { $imagesize = getimagesize($img_src); if ($imagesize['0'] > 210) { Code (markup): Would be a good start -- naturally you'd have to keep going on stripping out all the stupid malfing <?php ?> "for nothing" that are in there, and add a else handler for when there's an error trying to process the image at the appropriate spot.
Can you make sure that allow_url_fopen setting in php.ini is enabled, otherwise you won't be able to work with URLs with getimagesize. Alternatively, you can change it so that you use local absolute/relative paths instead or URLs. http://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen