matthewjumpsoffbuildings Posted August 19, 2008 Share Posted August 19, 2008 I'm using PHP+MySQL to build a CMS. Its going pretty well. I have one problem... The CMS uses mod_rewrite to change www.site.com/section/page into GET vars. Sometimes, I have a folder like www.site.com/xml - this contains an index.php, and then different pages get included depending on the URL, eg www.site.com/xml/newsfeed includes the newsfeed.php file in the xml folder. This is fine. But I have a flash file that simultaneously requests 4 files from the xml folder, which basically calls index.php 4 times with different included pages, all using the CMS to generate the content. I seem to get really bad performance sometimes. Sometimes it will load straight away, but then it seems if i reload the page it will take 30+ seconds sometimes. Its weird, in firebug the net monitoring shows the requests, it usually loads a couple of the xml/filename files, but i dont see the other 2 even tho the first couple are done... Also, i put some speed tester code in the php's and they all say they take something like 0.02 seconds to generate...it just seems to take ages to get back to the browser or something. Each call to xml/file opens the index.php in /xml, which then looks in the cache folder to see if xml/file has been cached yet, if so it echos its contents, else it connects to the database, generates the content, creates the cached file, then echos it out Any ideas why the bottlenecks are occuring? The site is http://mamajazz.com.au/ Quote Link to comment https://forums.phpfreaks.com/topic/120360-really-slow-response-times/ Share on other sites More sharing options...
matthewjumpsoffbuildings Posted August 19, 2008 Author Share Posted August 19, 2008 Its been suggested this could be to do with mod_rewrite. The rule im using is RewriteEngine on RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [NC] RewriteRule ^([^/\.]+)/([^/\.]+)/?$ index.php?section=$1&page=$2 [NC] RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ index.php?section=$1§ion2=$2&page=$3 [NC] RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ index.php?section=$1§ion2=$2§ion3=$3&page=$4 [NC] RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ index.php My other thought is - could it be some unclosed connection to a database or some unclosed link to a dir/file - something like that??? Can anyone offer any tips of common things to ensure are done to properly terminate a script im using mysql connections, reading contents of files, writing files, using output buffering, and using sessions. im also using register_shutdown_function to do things like close sessions and close output buffers... Quote Link to comment https://forums.phpfreaks.com/topic/120360-really-slow-response-times/#findComment-620282 Share on other sites More sharing options...
Third_Degree Posted August 19, 2008 Share Posted August 19, 2008 My other thought is - could it be some unclosed connection to a database or some unclosed link to a dir/file - something like that??? No, PHP automatically closes these types of things. Quote Link to comment https://forums.phpfreaks.com/topic/120360-really-slow-response-times/#findComment-620300 Share on other sites More sharing options...
matthewjumpsoffbuildings Posted August 19, 2008 Author Share Posted August 19, 2008 Are you sure? And if not, what else do you think it could be? Quote Link to comment https://forums.phpfreaks.com/topic/120360-really-slow-response-times/#findComment-620328 Share on other sites More sharing options...
matthewjumpsoffbuildings Posted August 19, 2008 Author Share Posted August 19, 2008 I seem to have ruled out mod_rewrite loop issues... so what else could it be??? Quote Link to comment https://forums.phpfreaks.com/topic/120360-really-slow-response-times/#findComment-620486 Share on other sites More sharing options...
matthewjumpsoffbuildings Posted August 20, 2008 Author Share Posted August 20, 2008 matthewBumpsOffBuildings Quote Link to comment https://forums.phpfreaks.com/topic/120360-really-slow-response-times/#findComment-620776 Share on other sites More sharing options...
cooldude832 Posted August 20, 2008 Share Posted August 20, 2008 My cms uses mod rewrite to refilter all request that end in .php to my index page so mysite.com/stuff/page1.php goes to mysite.com/index.php?page=stuff/page1.php and then it prepares content outta a database based on the get variable $_GET['Page']; the mod looks like Options +FollowSymLinks Options +Indexes RewriteEngine on RewriteBase / RewriteCond %{SCRIPT_FILENAME} !=/htdocs/index.php [NC] RewriteRule ^(.+)\.php$ index.php?Page_Request=$1&request=1 [QSA,L] RewriteRule ^$ index.php?Page_Request=index&request=1 [QSA,L] Note the RewriteCond you can exclude files you want from the rewrite rule allowing you to bypass folders you want to bypass Hope it helps gives you an idea. Note this only rewrites files ending in .php so a .xml file is safe Quote Link to comment https://forums.phpfreaks.com/topic/120360-really-slow-response-times/#findComment-620788 Share on other sites More sharing options...
matthewjumpsoffbuildings Posted August 20, 2008 Author Share Posted August 20, 2008 its not that i dont want files in the xml folder to be rewritten - in fact i do. what im asking is - is theres something wrong with the mod_rewrite rules i posted, or should they work ok. if they are ok, what could be causing this massive lag in request response despite the fact in the response the timer says the php took mere milliseconds to generate? Quote Link to comment https://forums.phpfreaks.com/topic/120360-really-slow-response-times/#findComment-620795 Share on other sites More sharing options...
matthewjumpsoffbuildings Posted August 20, 2008 Author Share Posted August 20, 2008 Hmmm someone mentioned it could be to do with PHP SESSIONS... As long as a php session is opened, no other scripts are allowed to open the same session (to avoid threading issues with the session data), and PHP will block on any call, even an implicit one, to open that session. Using sessions can cause slow loading behavior if you're including lots of php-served files into the same parent page. In some, rare, cases with web services calling eachother I've even seen php grind to a halt completely until the request timed out. This is what im doing - using sessions for lots of php created pages using the same parent php page... Any ideas how to get around this? I need the session open on each one so i can write to it throughout the script execution, so what i was doing was session_start(); function sessionCloseFunc(){ session_write_close(); } register_shutdown_function(sessionCloseFunc); Is there a way to have 'shared' sessions for a parent page? or something like that??? Quote Link to comment https://forums.phpfreaks.com/topic/120360-really-slow-response-times/#findComment-620911 Share on other sites More sharing options...
matthewjumpsoffbuildings Posted August 24, 2008 Author Share Posted August 24, 2008 Well Im pretty sure it's sessions - I removed session handling from my php and it seems to be fine. Problem is I need it How can I get sessions to work in a php file that may be called several times, simultaneously, from the same client? Quote Link to comment https://forums.phpfreaks.com/topic/120360-really-slow-response-times/#findComment-624026 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.