jordanwb Posted July 22, 2008 Share Posted July 22, 2008 I'm making a Photo system for a high school teacher. I have the following files (there's more but...): ./admin/index.php ./system/session.php ./index.php Both index.php files include session.php (the paths are correct). When I point my browser to http://192.168.1.131/photos/index.php it loads fine with no problems. But if I go to http://192.168.1.131/photos/admin/index.php it says that it's used it's allotment of 16 MB, so I increased it to 32MB, and I still get the error. The specific error is: Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 19456 bytes) in /var/www/photos/system/session.php on line 200 At line 200 is set_cookie (or setcookie whichever it is) and it doesn't actually run that code, it exists in a login function. I was wondering how to find out what's supposedly using all my ram. Quote Link to comment https://forums.phpfreaks.com/topic/116016-solved-im-getting-a-memory-leak-or-something/ Share on other sites More sharing options...
trq Posted July 22, 2008 Share Posted July 22, 2008 Are you resizing images on the fly? That can eat up allot of resources. Quote Link to comment https://forums.phpfreaks.com/topic/116016-solved-im-getting-a-memory-leak-or-something/#findComment-596506 Share on other sites More sharing options...
wrathican Posted July 22, 2008 Share Posted July 22, 2008 also ive found that some jpeg/jpg seem to be encoded differently to how php expects them to be therefore it tires to mess with the image but it cant. Quote Link to comment https://forums.phpfreaks.com/topic/116016-solved-im-getting-a-memory-leak-or-something/#findComment-596508 Share on other sites More sharing options...
jordanwb Posted July 22, 2008 Author Share Posted July 22, 2008 Are you resizing images on the fly? That can eat up allot of resources. Nope. I do do image resizing but not when viewing ./admin/index.php The thing is ./admin/index.php and ./index.php parse the same files; ./index.php uses for memory (./admin/index.php isn't finished), but I get the error on ./admin/index.php Quote Link to comment https://forums.phpfreaks.com/topic/116016-solved-im-getting-a-memory-leak-or-something/#findComment-596511 Share on other sites More sharing options...
revraz Posted July 22, 2008 Share Posted July 22, 2008 You are setting cookies at line 200? May want to rethink your logic. Quote Link to comment https://forums.phpfreaks.com/topic/116016-solved-im-getting-a-memory-leak-or-something/#findComment-596515 Share on other sites More sharing options...
trq Posted July 22, 2008 Share Posted July 22, 2008 Are you resizing images on the fly? That can eat up allot of resources. Nope. Then you might want to explain exactly what your code does. Otherwise, were just guessing. Quote Link to comment https://forums.phpfreaks.com/topic/116016-solved-im-getting-a-memory-leak-or-something/#findComment-596516 Share on other sites More sharing options...
jordanwb Posted July 22, 2008 Author Share Posted July 22, 2008 You are setting cookies at line 200? May want to rethink your logic. Ahem: At line 200 is set_cookie (or setcookie whichever it is) and it doesn't actually run that code, it exists in a login function. I was wondering how to find out what's supposedly using all my ram. Then you might want to explain exactly what your code does. Otherwise, were just guessing. If you like I could upload the code into a tar.gz file and upload a database dump. Quote Link to comment https://forums.phpfreaks.com/topic/116016-solved-im-getting-a-memory-leak-or-something/#findComment-596519 Share on other sites More sharing options...
jordanwb Posted July 22, 2008 Author Share Posted July 22, 2008 Update: I made a somewhat empty file in ./admin/ called test.php: <?php include ("../system/session.php"); ?> And I get: Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 19456 bytes) in /var/www/photos/system/session.php on line 279 So the code at that line is not relevant. In test.php I don't even make any instances, and none are made in the classes that are included is session.php Quote Link to comment https://forums.phpfreaks.com/topic/116016-solved-im-getting-a-memory-leak-or-something/#findComment-596692 Share on other sites More sharing options...
trq Posted July 22, 2008 Share Posted July 22, 2008 I'm not sure what you want us to do? We need to see some relevent code. Quote Link to comment https://forums.phpfreaks.com/topic/116016-solved-im-getting-a-memory-leak-or-something/#findComment-596694 Share on other sites More sharing options...
jordanwb Posted July 22, 2008 Author Share Posted July 22, 2008 All right, I'll upload the source code and the sql database. In the photos_users table the password is encrypted once with md5. Any other tidbits about security would be helpful too. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/116016-solved-im-getting-a-memory-leak-or-something/#findComment-596699 Share on other sites More sharing options...
revraz Posted July 22, 2008 Share Posted July 22, 2008 sessions.php is the page with the problem it seems. Quote Link to comment https://forums.phpfreaks.com/topic/116016-solved-im-getting-a-memory-leak-or-something/#findComment-596707 Share on other sites More sharing options...
jordanwb Posted July 22, 2008 Author Share Posted July 22, 2008 Well I'm not sure. If you go to ./index.php it's fine, but if you go to ./admin/index.php is panics. Quote Link to comment https://forums.phpfreaks.com/topic/116016-solved-im-getting-a-memory-leak-or-something/#findComment-596713 Share on other sites More sharing options...
revraz Posted July 22, 2008 Share Posted July 22, 2008 and you didn't include the code for either one of those pages. Quote Link to comment https://forums.phpfreaks.com/topic/116016-solved-im-getting-a-memory-leak-or-something/#findComment-596727 Share on other sites More sharing options...
wildteen88 Posted July 22, 2008 Share Posted July 22, 2008 I have downloaded and ran your code, index.php worked fine as you said, however for admin/index.php it did take a while to load and then nothing happened after a couple of secounds. After doing a lot of commenting/uncommenting of lines I narrowed it down to the following line in system/sessions.php include ("settings.php"); For some reason PHP would crash, I got no error messages, just plank page. I found this strange as I have error_reporting set to E_ALL and display_errors enabled. Once I commented that line out everything worked fine, and I got a screen full of errors. Next I decided to copy the code in setting.php to system/session.php and everything worked nicely. So my conclusion is to do with how PHP is trying to include files. Maybe you should rethink your file structure. Quote Link to comment https://forums.phpfreaks.com/topic/116016-solved-im-getting-a-memory-leak-or-something/#findComment-596739 Share on other sites More sharing options...
jordanwb Posted July 22, 2008 Author Share Posted July 22, 2008 and you didn't include the code for either one of those pages. Wha? I have downloaded and ran your code, index.php worked fine as you said, however for admin/index.php it did take a while to load and then nothing happened after a couple of secounds. After doing a lot of commenting/uncommenting of lines I narrowed it down to the following line in system/sessions.php include ("settings.php"); For some reason PHP would crash, I got no error messages, just plank page. I found this strange as I have error_reporting set to E_ALL and display_errors enabled. Once I commented that line out everything worked fine, and I got a screen full of errors. Next I decided to copy the code in setting.php to system/session.php and everything worked nicely. So my conclusion is to do with how PHP is trying to include files. Maybe you should rethink your file structure. Is PHP trying to find settings.php in the ./admin folder? Whenever I make a website in PHP I get confused with file paths, and how PHP uses them. Got any other suggestions regarding code? Improvements, bad ideas? I changed these lines: include ("../system/session.php"); include ("system/admin_menu.php"); to this: chdir ("../system"); include ("../system/session.php"); chdir ("../admin"); include ("system/admin_menu.php"); and now it works, albeit a bit of a kludge. Quote Link to comment https://forums.phpfreaks.com/topic/116016-solved-im-getting-a-memory-leak-or-something/#findComment-596834 Share on other sites More sharing options...
wildteen88 Posted July 22, 2008 Share Posted July 22, 2008 Na, do not use chdir. I recommend you setup a few constants in session.php, call these BASE and ADMIN_BASE like so: define('SYS', dirname(__FILE__)); define('ADMIN_SYS', dirname(SYS) . '/admin/system'); When ever you include a file from system directory, do include SYS . '/file.php'; To include a file from admin system directory, do include ADMIN_SYS . '/file.php'; You'll have to use a relative path though to include system/session.php as that is where the constants are defined. Quote Link to comment https://forums.phpfreaks.com/topic/116016-solved-im-getting-a-memory-leak-or-something/#findComment-596867 Share on other sites More sharing options...
jordanwb Posted July 22, 2008 Author Share Posted July 22, 2008 Is there some particular reason not to use chdir? Any other suggestions regarding the improvement of any of my code? Quote Link to comment https://forums.phpfreaks.com/topic/116016-solved-im-getting-a-memory-leak-or-something/#findComment-596909 Share on other sites More sharing options...
wildteen88 Posted July 23, 2008 Share Posted July 23, 2008 chdir just adds more complexity to your script (I have never used it). My suggestion is a lot easier to maintain. Quote Link to comment https://forums.phpfreaks.com/topic/116016-solved-im-getting-a-memory-leak-or-something/#findComment-597691 Share on other sites More sharing options...
jordanwb Posted July 23, 2008 Author Share Posted July 23, 2008 I see. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/116016-solved-im-getting-a-memory-leak-or-something/#findComment-597825 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.