sleep() is clearing my array? :(

Discussion in 'PHP' started by Choller, Sep 19, 2007.

  1. #1
    I'm working on my own cms and i'm running into a weird but extremely frustrating problem.

    I'm using sleep() in the script to delay a process. But...

    Really basic example

    
    set_time_limit( 0 );
    $go[]='2';
    $go[]='4';
    $go[]='1';
    
    sleep(2);
    print_r($go);
    
    PHP:
    If I put print_r before the sleep it outputs, if I put it after sleep then it doesn't output anything.

    I don't know wtf could be doing this and i've been staring at it for 90mins already so I'm looking for some help.
     
    Choller, Sep 19, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    I can't reproduce the error, this works just fine for me.
     
    nico_swd, Sep 19, 2007 IP
  3. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #3
    Try this?
    <?php
    
    error_reporting(E_ALL);
    ini_set('display_errors', true);
    set_time_limit( 0 );
    
    $go = array();
    $go[]='2';
    $go[]='4';
    $go[]='1';
    
    sleep(2);
    var_dump($go);
    PHP:
    You should at very least get "NULL"...
     
    krt, Sep 19, 2007 IP
  4. Choller

    Choller Peon

    Messages:
    388
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Man how the F is this possible? It's just not outputting anything. I tried the example above but I just don't get any output.

    I even gave it a new variablename and tried echo'ing it in the end..... f'ing still blank.

    This is driving me CRAZY!!
     
    Choller, Sep 21, 2007 IP
  5. Im The ONE

    Im The ONE Peon

    Messages:
    800
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    0
    #5
    No idea about this, maybe if you're using php4 try in php5.
     
    Im The ONE, Sep 21, 2007 IP
  6. Nikolas

    Nikolas Well-Known Member

    Messages:
    1,022
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    150
    #6
    Wait a second. Do you run this from a browser? If yes then the request times out.

    Your code works with php4 as well (checked it, just in case).
     
    Nikolas, Sep 21, 2007 IP