Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. randomly generate a number every X minutes (php)

randomly generate a number every X minutes (php)

Scheduled Pinned Locked Moved Web Development
tutorialquestionphp
9 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    Yustme
    wrote on last edited by
    #1

    Hi, How can i randomly generate a number every (for example) 20 minutes with php? I know how to generate a number, but i have no idea how to make it generate one every X minutes. Thanks in advance!

    L T 2 Replies Last reply
    0
    • Y Yustme

      Hi, How can i randomly generate a number every (for example) 20 minutes with php? I know how to generate a number, but i have no idea how to make it generate one every X minutes. Thanks in advance!

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      This may sound like an obvious answer but you just put your random number generator in a loop, and include whatever PHP command is required to sleep for 20 minutes each time around the loop.

      Y P 2 Replies Last reply
      0
      • L Lost User

        This may sound like an obvious answer but you just put your random number generator in a loop, and include whatever PHP command is required to sleep for 20 minutes each time around the loop.

        Y Offline
        Y Offline
        Yustme
        wrote on last edited by
        #3

        I dont want the app to sleep. It has several other things to do. Got another suggestion?

        L 1 Reply Last reply
        0
        • Y Yustme

          I dont want the app to sleep. It has several other things to do. Got another suggestion?

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Sorry no, I guess you have to find some way of checking the time every so often and after twenty minutes call your generator function.

          1 Reply Last reply
          0
          • L Lost User

            This may sound like an obvious answer but you just put your random number generator in a loop, and include whatever PHP command is required to sleep for 20 minutes each time around the loop.

            P Offline
            P Offline
            plecco
            wrote on last edited by
            #5

            I suggest you take the initial idea and find a way to create another process to do the other tasks that need to be done...I other words, you'll perform the update the time and sleep for 20 mins on one process thread and on the other thread you'd perform the remaining tasks. Hope this helps.

            Plecco Technologies, Inc. Web Design | Software Development | Internet Marketing

            modified on Wednesday, January 27, 2010 10:00 AM

            L 1 Reply Last reply
            0
            • P plecco

              I suggest you take the initial idea and find a way to create another process to do the other tasks that need to be done...I other words, you'll perform the update the time and sleep for 20 mins on one process thread and on the other thread you'd perform the remaining tasks. Hope this helps.

              Plecco Technologies, Inc. Web Design | Software Development | Internet Marketing

              modified on Wednesday, January 27, 2010 10:00 AM

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              This message needed to be posted to the original questioner.

              P 1 Reply Last reply
              0
              • L Lost User

                This message needed to be posted to the original questioner.

                P Offline
                P Offline
                plecco
                wrote on last edited by
                #7

                Sorry I just joined and am learning the format for forum post.

                Plecco Technologies, Inc. Web Design | Software Development | Internet Marketing

                modified on Wednesday, January 27, 2010 9:57 AM

                L 1 Reply Last reply
                0
                • P plecco

                  Sorry I just joined and am learning the format for forum post.

                  Plecco Technologies, Inc. Web Design | Software Development | Internet Marketing

                  modified on Wednesday, January 27, 2010 9:57 AM

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  plecco wrote:

                  Sorry I just joined and am learning the format for forum post.

                  May I suggest you spend time in "read only" mode until you are more familiar with how the forums operate, before starting to answer queries. That is, unless you absolutely have the solution to a poster's question.

                  1 Reply Last reply
                  0
                  • Y Yustme

                    Hi, How can i randomly generate a number every (for example) 20 minutes with php? I know how to generate a number, but i have no idea how to make it generate one every X minutes. Thanks in advance!

                    T Offline
                    T Offline
                    Terry Valladon
                    wrote on last edited by
                    #9

                    I may be a tad late to the game here but if you are using Linux or Mac this should work fine for your needs. --Terry Valladon $random_number = rand(); // I will let you worry about seeds and stuff, perhaps call your own make_random() function? print('Random number is '.$random_number."\n"); declare(ticks = 1); // Set ticks to one second pcntl_signal(SIGALRM, "signal_handler"); // Installs a signal handler for SIGALARM (works in linux/mac only I think) pcntl_alarm(1200); //trigger alarm in 20 min (60 seconds * 20 min = 1200 seconds) // This is just to keep the script running forever, I would HOPE you would have real code in here rather then just looping endlessly. for(;;) { sleep(1); } function signal_handler($signal) { global $random_number; switch($signal) { case SIGALRM: $random_number = rand(); // New random number, I will let you worry about seeds and stuff, perhaps call your own make_random() function? print('New random number is '.$random_number."\n"); pcntl_alarm(1200); //trigger alarm again in 20 min break; // Exit function and continue normal code execution. } }

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups