Northern Flame Posted February 13, 2008 Share Posted February 13, 2008 I am wondering how PHP reads files? I am writing a script that is pretty big, a few hundred lines. The main statement in my script is a switch() statement and that switch() statement checks for different $_GET values that will decide what the page will do. I was wondering if it would be faster to have separate pages for each thing instead of having the switch() or does PHP just skip the values in the switch() that dont apply to my $_GET value and it makes no difference in the speed of the page loading time. Does anyone know the answer to my question? Quote Link to comment Share on other sites More sharing options...
haku Posted February 13, 2008 Share Posted February 13, 2008 After it comes to the applicable switch statements, it executes the code within until it comes to 'break', then skips to the next part of your script. Quote Link to comment Share on other sites More sharing options...
Northern Flame Posted February 13, 2008 Author Share Posted February 13, 2008 yea but does it skip all the cases that are set before the case that actually applies to that page or does it read through each case before the one that applies? Quote Link to comment Share on other sites More sharing options...
teng84 Posted February 13, 2008 Share Posted February 13, 2008 yeah less script runs fast even if php is not executing your code because it doesnt meet your condition still php will scan your script and check it.. separating the file.... this actually depends let say you have 100 functionality would you like to have 100 page for each functionalities? or combine related functionalities in one page to produce 5 - 10 page? now what is better? Quote Link to comment Share on other sites More sharing options...
Northern Flame Posted February 13, 2008 Author Share Posted February 13, 2008 well i only have about 5 or 6 things that the switch statement holds but each thing is pretty long. Thats what I was wondering, but maybe ill just keep it all on one script. Quote Link to comment Share on other sites More sharing options...
Northern Flame Posted February 13, 2008 Author Share Posted February 13, 2008 ey what happened to the topic solved button?! ??? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 13, 2008 Share Posted February 13, 2008 You could put the code in each "case" block into separate files and "include()" them. BTW, a few hundred lines isn't very big... The "Solved" button went MIA when the forums were upgraded a few days ago. Ken Quote Link to comment Share on other sites More sharing options...
Northern Flame Posted February 13, 2008 Author Share Posted February 13, 2008 i know a few hundred lines isnt big, but im still not done writing the file, i was in the middle of writing it and thats when i started wondering how PHP read the script, but thanks for all the replies! Quote Link to comment Share on other sites More sharing options...
haku Posted February 13, 2008 Share Posted February 13, 2008 I believe it doesn't read the code inside the 'case' statement if that statement doesn't apply. So the length of script in each case statement shouldn't matter. Quote Link to comment Share on other sites More sharing options...
teng84 Posted February 13, 2008 Share Posted February 13, 2008 I believe it doesn't read the code inside the 'case' statement if that statement doesn't apply. So the length of script in each case statement shouldn't matter. i believe it reads the file but it doesn't execute the file ! Quote Link to comment 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.