CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2008
    Posts
    9

    PHP - Function stops mid-loop.

    I have a PHP script that is supposed to do some processing on about 20Kb of data and echo it to the screen.

    The loop just stops at the exact same location every time. No error message or anything. It does not continue to execute any code after the function either.

    I know that I am not reaching the 30 sec max execution time (it takes <2 seconds), and that I am not trying to echo too much data to the screen (it stops at about 12 Kb).

    Here is a sample piece of code that generates the problem (at lease on my computer)...

    Code:
    for ($i = 0;$i < 10000000; $i ++)
    {
    	echo $i . "-";
    }
    Every time it ends at the same number: "2127".

    I've searched the web, but didn't find anything. It's hard to know what to Google when I'm not quite sure what my problem is.


    -Scott

  2. #2
    Join Date
    Jun 2008
    Posts
    9

    Re: PHP - Function stops mid-loop.

    Sorry to double post, but here is some extra information...

    The below code stops at the same number and does print it to the browser after the loop.

    Code:
    $a = "";
    for ($i = 0;$i < 5000; $i ++)
    {
    	$a .= $i . "-";
    }
    echo $a;
    .NET 2.0

  3. #3
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    106

    Re: PHP - Function stops mid-loop.

    Its not your code, it runs ok when I test it.
    Maybe check webserver and php config

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

    Re: PHP - Function stops mid-loop.

    Also check your error log. It's possible that your have passed your time limit of PHP execution.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    Jun 2008
    Posts
    9

    Re: PHP - Function stops mid-loop.

    I checked all of my logs and settings. The page takes under 2 seconds to load and my max_execution_time is set to the standard 30.

    Just to be sure I tried it on 2 separate servers - same problem.

    The page loads a different amount of data when viewed in a different browser, yet it still doesn't load the whole page.

  6. #6

    Re: PHP - Function stops mid-loop.

    Could it be that there's some terminating character in your document (or, the data you are processing) at that position? I thought of this because Teranoz tested your code, and it runs fine on his end (assuming he used a different file).

    Also, a counter-test would be to change the increment (for example, increment $i by 2 in every loop iteration), and see where it stops then.
    A few friendly reminders:
    * Use Code Tags when posting code.
    * Rate good replies/post by clicking "Rate this Post" and leaving a positive feedback.
    * Things should be made as simple as possible, but not any simpler. -- Albert Einstein

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