loading multiple files at the same time...?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phoenix121
Forum Commoner
Posts: 28
Joined: Sun Sep 25, 2005 9:09 pm
Location: New Zealand

loading multiple files at the same time...?

Post by phoenix121 »

Is there any possible way using PHP to request multiple HTML files at the same time? at the moment, my script is something like this:

Code: Select all

for ($i=1; $i<10; $i++){
doSomething();
}
what i want is to put the doSomething() into a different PHP file, so when i call it using something like file_get_contents() it gets executed. But if i use file_get_contents(), it will wait for the whole file to get loaded before doing it the next time, which defeats the purpose. Is there any code that might help?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

concurrent loading isn't very possible with PHP. It's not a multithreaded language in that regard, or any regard that I know of. The best you may be able to do is shunt it to a separate script via a shell execution. However I'm not sure that'd work either. Using shared memory should technically make it possible, but somewhat difficult to synchronize.
phoenix121
Forum Commoner
Posts: 28
Joined: Sun Sep 25, 2005 9:09 pm
Location: New Zealand

Post by phoenix121 »

my friend had a new idea:

Code: Select all

// a.php //

for ($i=1; $i<10; $i++) {
  file_get_contents('b.php');
}

// b.php //

header("location: c.php");
doSomething();

// c.php //
// (empty)
his idea is to trick the script into thinking that 'b.php' is empty, so that 'a.php' will continue and execute 'b.php' again straight away, while 'b.php' executes the 'doSomething()' function concurrently. is this possible?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Try it. You'll find out pretty quickly. :)
phoenix121
Forum Commoner
Posts: 28
Joined: Sun Sep 25, 2005 9:09 pm
Location: New Zealand

Post by phoenix121 »

i'll take that as a no :D thats what i thought too, but i just thought i'd ask before trying ;)
yum-jelly
Forum Commoner
Posts: 98
Joined: Sat Oct 29, 2005 9:16 pm

Post by yum-jelly »

If your using Unix/Linux, then use PHP(s) pcntl_fork() function and then create some children to do your dirty work, LoL, who can run in parallel (run at the same time) On windows you can only do this Perl, thanks to Microsoft paying the O'Reilly team to add fork() elimination to the Perl compiler...


yj
Post Reply