Page 1 of 1

need help please ^_^

Posted: Thu Jun 04, 2009 10:43 am
by olivarra
i've this code:

Code: Select all

<?php
    class test{
        public function test(){
            echo "starting infite loop<br />";
            for(;;);
            echo "this missage never shows<br />";
        }
    }
    set_time_limit(3);
    $var = new test();
    echo "finish<br />";
?>
what i want to see is:
starting infinite loop
finish
(Error of timeout)

but what i get is:
starting infite loop
(Error of timeout)

the question is: is there anyway to get the class test working while the main works too?

thank you very much,
olivarra1

Re: need help please ^_^

Posted: Thu Jun 04, 2009 10:47 am
by Chalks
What's happening is this:

Code: Select all

  set_time_limit(3);  //timeout after 3 seconds
  $var = new test();  // try to do this for 3 seconds
  echo "finish<br />";  // now do this
As far as I know, there's no way to have it do two things at the same time. I could be wrong, however. Why are you trying to accomplish this?

Re: need help please ^_^

Posted: Thu Jun 04, 2009 11:00 am
by olivarra
uhhm.... set_time_limit is not for setting the timeout of all the script?

it's because i want the class test to get some timing loops (using microtime):

Code: Select all

$start=microtime();
while(microtime() < $start + 1000);
, while the main code continues doing its job

i thought about:

Code: Select all

<?php
    class test{
        private $start;
        public function test(){
            $this->start = microtime();
        }
        public function compare(){
            if(microtime() >= $start + 1000){
                //Do what u have to do
            }
        }
    }
    set_time_limit(0);
    $var = new test();
    while(1){
        //Do what u have to do
        $var->compare();
    }
?>
but i think it'll be more easy to get like AS3 does...

anywat, i got another question, using the code above:

Code: Select all

class test{
        private $start;
        public function test(){
            $this->start = microtime();
        }
    }
is there any way to quit those $this-> every time i use a global variable of the class? i've got few classes that there's a lot of $this-> and it bothers me...

ty,
olivarra1