need help please ^_^

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
olivarra
Forum Newbie
Posts: 4
Joined: Thu Apr 24, 2008 4:05 pm

need help please ^_^

Post 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
User avatar
Chalks
Forum Contributor
Posts: 447
Joined: Thu Jul 12, 2007 7:55 am
Location: Indiana

Re: need help please ^_^

Post 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?
olivarra
Forum Newbie
Posts: 4
Joined: Thu Apr 24, 2008 4:05 pm

Re: need help please ^_^

Post 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
Post Reply