Page 1 of 1

loading multiple files at the same time...?

Posted: Sat Oct 29, 2005 3:54 am
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?

Posted: Sat Oct 29, 2005 5:40 am
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.

Posted: Sat Oct 29, 2005 10:22 pm
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?

Posted: Sat Oct 29, 2005 10:27 pm
by feyd
Try it. You'll find out pretty quickly. :)

Posted: Sat Oct 29, 2005 10:59 pm
by phoenix121
i'll take that as a no :D thats what i thought too, but i just thought i'd ask before trying ;)

Posted: Sun Oct 30, 2005 6:49 am
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