Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Sep 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Parallel Processing in PHP

    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
    ..............................

  • #2
    Senior Coder gsnedders's Avatar
    Join Date
    Jan 2004
    Posts
    2,340
    Thanks
    1
    Thanked 7 Times in 7 Posts
    The slow down is caused by opening the other files, getting the data across the internet, the only real way to speed it up is to cache the files.

  • #3
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by alirizwan
    Is there any way that i can open both or more files Simultaneous ?
    How can i execute some my code in parallel processing?
    I might be wrong, but i don't think you can using PHP.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #4
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    There might be a "way" but I'm 99,9% sure it won't work on any server. You'd have to do it in another way like Error said.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •