Forum Moderators: coopster

Message Too Old, No Replies

Php Includes and require

         

Tommybs

6:37 pm on Jan 18, 2008 (gmt 0)

10+ Year Member



Hi all,

I'm a fairly experienced programmer in terms of working things out etc. and I know the differnce in terms of includes and require statements. But in terms of how php 'works' I still have a lot to learn in that area.

Now my question regarding includes and requires is:

Are the files in these statements 'included' after the base file has loaded or does the compile merge them all together at runtime as it were and process it as one file?

The reason I ask is because, if you had a file with lots of includes, is it possible to load the basepage and then display a loading indicator using some javascript or ajax etc. to show where another file is loading (if it is an especially large file). Almost as if the included file is a control that, although is part of the page, it's almost as if it is viewed as a seperate section (like an image gallery might have a loading indicator when a new image is loading.)

Hope that is clear enough.

Many Thanks

eelixduppy

7:09 pm on Jan 18, 2008 (gmt 0)



I'm pretty sure that you cannot do that with includes or requires. As I understand, the php interpreter includes the file when it comes to it, and then interprets the included file at that point. It will stop due to certain conditions such as the file being successfully included or if the file is missing, et cetera. Once one of these conditions are met, then it continues with the interpretation of the rest of the script.

I feel like the only way to include a large file and have a loading screen is if you combined javascript, ajax, and php together in one application. The javascript and the ajax would send a request to the server to load the file, and if need be send pertinent information to the script. The ajax would continue to show a loading graphic until ajax actually receives a reply from the server. At that time you would end the loading screen or whatever and output the data to the screen.

Experiment with a few things and see how it works. If you find other solutions, please be sure to post them here for other member to see.

Tommybs

8:31 pm on Jan 18, 2008 (gmt 0)

10+ Year Member



I thought about it after I posted actually and remembered "PHP is a server side scripting language" so I thought it will all be compiled as 1 page first. Nevermind I'll have a little play around anyway i guess. Thanks for replying though

Tommybs

9:36 am on Jan 19, 2008 (gmt 0)

10+ Year Member



Just been thinking more about this, and I thought of an idea. What if the content itself was php and mysql driven but the output is then parsed into an xml file. I don't really use xml once but I know enough to create with php etc. Does this sound like it could be a possibilty to show the content is loading?

Thanks

ChainsawXIV

8:38 am on Jan 20, 2008 (gmt 0)

10+ Year Member



If I read you correctly, what you're describing in your latest post is basically an AJAX setup - you serve a simple starting page that tells the user it's "Loading...", and then uses JavaScript to fetch the actual content from another server script, and replace the loading message with it once it's done downloading. If that's the case, you may find this <snip>handy. I know I did.

[edited by: ChainsawXIV at 8:39 am (utc) on Jan. 20, 2008]

[edited by: dreamcatcher at 10:01 am (utc) on Jan. 20, 2008]
[edit reason] no urls as per T.O.S [webmasterworld.com].Thanks [/edit]