CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2005
    Posts
    73

    Avoid php "hanging" page

    Hello,
    I have a php page that the user enters some data in a textarea, and then this data is fed into a command line program. When the execution of the command line programm finishes, the results are stored in an output file that is created. The "results" php page then reads this file and the user views the results. My problem is that sometimes (depending on the amount of data inserted and, subsequently the size of the output file created by the command-line programm), the php results page crushes, outputting error like:

    Code:
    Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 846269 bytes) in /results.php on line 125
    In this line of the script, I read the whole file into a string and then separate each result chunk by a separator (//) that the command line programm creates:

    Code:
     $res_handle= fopen($output_file, "r");
     $results = fread($res_handle, filesize($output_file));
     fclose($res_handle);
                        
     $separated_entries = explode ("//", $results);
    Then, foreach chunk, I output the results to the user. Is there something that I must configure in php so that it won't have memory problems? Or another way to slurp the total output file without exhausting the memory?

    thank you!

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: Avoid php "hanging" page

    Change the memory_limit setting in your php.ini configuration. Alternatively, you can set it using PHP as well.

    PHP Code:
    ini_set("memory_limit""32M"); 
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured