If I make a PHP loop will the code never get to the html

Discussion in 'PHP' started by Imozeb, Feb 11, 2010.

  1. #1
    If I make a PHP code loop since PHP is parsed first does that mean that the html in the page will never be executed until I exit the PHP loop. Is this the same with Javascript? Like the browser only reads one line at a time starting at the top with PHP right so it'll never get to the PHP and if it goes into a javascript loop it'll never get to the rest of the html code right?
     
    Imozeb, Feb 11, 2010 IP
  2. krsix

    krsix Peon

    Messages:
    435
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The browser does not read PHP. PHP is processed serverside before being sent to the browser.

    If you don't suppress errors, IIRC PHP does have a maximum execution time configurable, when it hits that it should error out and spit out the rest of the page
     
    krsix, Feb 11, 2010 IP
  3. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #3
    you have a point there, but no..

    there are two sides running scripts
    javascript -> frontend (browser)
    PHP -> serverside (apache)

    There will be no conflicts here because they are running in different environment. PHP error will halt the javascripts but not javascript stopping PHP, meaning the PHP (serverside) runs first.
     
    bartolay13, Feb 11, 2010 IP
  4. newgenservices

    newgenservices Well-Known Member

    Messages:
    862
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    105
    Digital Goods:
    1
    #4
    Enable error_reporting(E_ALL) and try to put some debug handlers and / or log them to a file on the server. So this way even if you don't see what is happening in the loop on browser, you can see the log for info.
     
    newgenservices, Feb 12, 2010 IP
  5. HivelocityDD

    HivelocityDD Peon

    Messages:
    179
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I like to tell you one thing here ... If you are creating an infinite loop inside php script and include it inside html it will not display any content as in server side the execution is not done yet.

    So make sure you dont have an infinite loop in php script .. otherwise you will get a blank page


    Thanks !
     
    HivelocityDD, Feb 12, 2010 IP
  6. [x[x]x]

    [x[x]x] Peon

    Messages:
    813
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #6
    in PHP there's a function called flush();

    as soon as you call flush it sends out all the available output from your php routine

    
    <?php 
    
    for ($i=1; $i<=50; $i++)
    {
         echo $i . "<br />";
         flush();
    }
    
    
    ?>
    
    PHP:
     
    [x[x]x], Feb 12, 2010 IP
  7. Brandon.Add.On

    Brandon.Add.On Peon

    Messages:
    178
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #7
    If you use the output buffer all your code will execute then be sent to the browser therefore if your code never finished executing ie inf loop no output will be sent to your browser. if you print your code right after you execute it then each print will be sent to your browser.
     
    Brandon.Add.On, Feb 12, 2010 IP
  8. Imozeb

    Imozeb Peon

    Messages:
    666
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Thanks everyone for answering my stupid question. :D

    ~imzoeb
     
    Imozeb, Feb 12, 2010 IP