Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Parallel Processing in PHP

Parallel Processing in PHP
Thread Tools
Fresh-Faced Recruit
Join Date: Sep 2005
Status: Offline
Reply With Quote
Sep 8, 2005, 06:48 PM
 
Hi,

I want to perform Parallel Processing in PHP. Let me try to explain my problem.
I want to open 2 files with fopen at the same time.

For Example first file takes 30 seconds and 30 seconds seond file to read in web.
and total time will be 60 seconds.
Can i read both files in 30 seconds with parallel execuation?

<?php

$handle_1 = fopen("www.domain.com/index.php", "r");
$text_1 = fread($handle_1,filesize("$handle_1"));
fclose($handle_1);

$handle_2 = fopen("www.domain.com/index.php", "r");
$text_2 = fread($handle_2,filesize("$handle_2"));
fclose($handle_2);

$text = $text_1 . $text_2;

print $text;

?>

As above code run line by line and takes much time. Is there any way that i can open both or more files Simultaneous ?
How can i execute some my code in parallel processing?


Regards,

Ali Rizwan (Web Developer)
Aztek Computers
http://www.aztekcomputers.com
..............................
     
Clinically Insane
Join Date: Nov 1999
Status: Offline
Reply With Quote
Sep 8, 2005, 07:16 PM
 
Unfortunately, it will take more than just parallel processing to help you here. If both files are on the same drive (or whatever storage unit you're using), even if you use parallel processing the machine will still have to open the files one at a time. Even though you might be reading in two files at once, it will take you the same amount of time to open both files as it did before.

What you would need to do in order to see any benefit would be to put the files on different devices -preferably on completely different I/O buses- and only then could you start your work with threads. The threads will be tricky too, because you have to make sure that the program doesn't continue past reading the files until both files are completely finished.

What are these files which are so big that reading them in takes 30 seconds each? Do you actually need all of the data in both of these files every time you run the app? If you don't need everything each time the app runs, then I would strongly consider rethinking the way you store your data. If you can do this, you'll probably get better performance than by using parallel processing. This may not be possible in your case -I would need to know more about what the files contain before I could help you decide that- but if you can do it then it will probably be better than trying to do parallel processing.
You are in Soviet Russia. It is dark. Grue is likely to be eaten by YOU!
     
Grizzled Veteran
Join Date: Oct 2003
Status: Offline
Reply With Quote
Sep 8, 2005, 10:04 PM
 
PHP doesn't support multi-threading.
The only thing necessary for evil to flourish is for good men to do nothing
- Edmund Burke
     
Clinically Insane
Join Date: Nov 1999
Status: Offline
Reply With Quote
Sep 9, 2005, 06:36 AM
 
Originally Posted by madmacgames
PHP doesn't support multi-threading.
Well then, there goes that idea.

Again, what's in those files? There may be a better way to store your data.
You are in Soviet Russia. It is dark. Grue is likely to be eaten by YOU!
     
Mac Elite
Join Date: Feb 2000
Location: Nashua NH, USA
Status: Offline
Reply With Quote
Sep 9, 2005, 09:49 AM
 
The biggest problem I see is that your reading two large files into memory then copying both of them into a third location. I's concatinate them on disk with cat and then read them into memory in smaller chunks, like 512B.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 07:35 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2