Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 10 of 10
  1. #1
    Join Date
    Jun 2006
    Posts
    4,832
    Tokens
    0

    Latest Awards:

    Default PHP continous loop?

    Hey, well basically I'm using a function that generates a random string, then in my PHP code it saves that string to a text file. It's only doing one at a time though (one per page load). Sure, if I reload the page it adds another, but one at a time is slow.

    I've used
    PHP Code:
    header('refresh:0; url=page.php'); 
    , but the problem with that is it keeps reloading the page... I want to just load the page and it creates a new string, saves it, creates a new string, saves it... and continues doing that X amount of time (x being infinite or 100).

    Is it possible to do this somehow? I've used google but it got confusing.

    Thanks.

  2. #2
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    PHP Code:
    <?php

    $times 
    100// times to run the script.

    for($i 0$i $times$i++) {
        
    // number generating code here. //
    }

    ?>

  3. #3
    Join Date
    Jun 2006
    Posts
    4,832
    Tokens
    0

    Latest Awards:

    Default

    Thanks Caleb! Works like a charm.

  4. #4
    Join Date
    Dec 2006
    Location
    Swindon
    Posts
    3,299
    Tokens
    215
    Habbo
    dunko

    Latest Awards:

    Default

    Or you could do (for unlimited)

    PHP Code:
    <?php
    $times 
    = -1// times to run the script.
    for($i 0$i != $times$i++) {
        
    // number generating code here. //
    }

    ?>
    should work
    Last edited by Blob; 10-04-2009 at 06:38 PM.

  5. #5
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    Quote Originally Posted by Blob View Post
    Or you could do (for unlimited)

    PHP Code:
    <?php
    $times 
    = -1// times to run the script.
    for($i 0$i != $times$i++) {
        
    // number generating code here. //
    }

    ?>
    should work
    Then the PHP script would timeout, and eventually the browser would timeout.

    Unless you was running it as a CLI application.

  6. #6
    Join Date
    May 2005
    Location
    San Francisco, CA
    Posts
    7,160
    Tokens
    2,331

    Latest Awards:

    Default

    Quote Originally Posted by Blob View Post
    Or you could do (for unlimited)

    PHP Code:
    <?php
    $times 
    = -1// times to run the script.
    for($i 0$i != $times$i++) {
        
    // number generating code here. //
    }

    ?>
    should work
    Or just something like
    PHP Code:
    while( true ) {


  7. #7
    Join Date
    Dec 2006
    Location
    Swindon
    Posts
    3,299
    Tokens
    215
    Habbo
    dunko

    Latest Awards:

    Default

    Quote Originally Posted by Invent View Post
    Or just something like
    PHP Code:
    while( true ) {

    Yeah but I wasnt that clever to think of a while

  8. #8
    Join Date
    Jun 2006
    Posts
    4,832
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Invent View Post
    Or just something like
    PHP Code:
    while( true ) {

    Oh darn, I was going to do that before I asked but I wasn't sure so I left it aha.

    So far I'm doing 100,000 working nicely.

    If I use what you posted for unlimited, how many do you reckon it'd do before timing out?

  9. #9
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    Depends on how you setup your server for max execution time, and the browser you're using.

    If you're generating things, and doing this for the hash, let me know.. and I can help you generate a big list.

  10. #10
    Join Date
    Jun 2005
    Posts
    4,795
    Tokens
    0

    Latest Awards:

    Default

    You can override PHP's max execution time but I would strongly recommend against it as it has the potential to overwhelm your server with the endless loop.

    PHP is not really the ideal language to be generating md5 hashes like that (I assume you are using this for your project) due to the overhead that comes with it. I'd recommend you use a language like C++ with a highly optimized MD5 hashing code and just dumping to a text file or if you wanted to insert directly into a mysql database you could have have one thread doing the hashing and another moving to MySQL. Although depending on how it may work out a backlog of MD5 hashes may occur and start to eat up your memory.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •