Welcome Guest, Not a member yet? Register   Sign In
PHP and Queue Systems?
#4

[eluser]ChrisMiller[/eluser]
[quote author="Aea" date="1201600393"]
Random Idea : Potentially an endless loop which checks the queue database every x seconds, does its job in that way, and it will be executed on PHP server start up? Of course, there'll need to be isolation so that if something that the queue executes results in an error the queue file doesn't go down with it. A bit of an inelegant solution, would prefer to find a way to know if a script is currently running.[/quote]

Same thing I was thinking about, write a controller and have it setup so it rechecks the queue and have the application go to sleep (http://us2.php.net/sleep) for 180 secs (3mins) or so and then after the sleep have it reload itself thus making a neverending loop. Now I would also add a function so you can throw a manual stop at it so you dont end up with a loop system that is hard to stop and neverending execution. Here is a quick example of a repeating class... I know its not the best but it gets the idea out...
Code:
<?php
class Queue {
    
    var $sleep = 180;
    
    function Queue()
    {

    }
    
    function process()
    {
        //-------------------------------------
        // Check for manual end here
        //-------------------------------------
        
        
        
        //-------------------------------------
        // Your Code (remember to trap errors)
        //-------------------------------------
        // Do your php here code...
        
        
        //-------------------------------------
        // Go to sleep for a bit...
        //-------------------------------------
        @sleep( $this->sleep );
        
        
        //-------------------------------------
        // Lets reload ourself to make a loop
        //-------------------------------------
        $this->process();
    }
    
}
?>

Now with that where you store the pending list you should have it setup with a priority list like said above thus important changes are pushed through first and non-important ones are just added to the end of the list but not forgotten. Now you say you would like to process more requests on off times then if you have php 5 then you might want to be interested in running a second looping script but instead have it run only during say 2am -> 5am then shutdown till 2am the next day using the following idea:
Code:
<?php
class Queue {
    
    var $sleep = 180;
    
    function Queue()
    {

    }
    
    function process()
    {
        //-------------------------------------
        // Check for manual end here
        //-------------------------------------
        
        
        
        //-------------------------------------
        // Your Code (remember to trap errors)
        //-------------------------------------
        // Do your php here code...
        
        
        //-------------------------------------
        // Go to sleep for a bit...
        //-------------------------------------
        if( time() >= mktime(4,0,1) )
        {
            // Before 4am keep running...
            @sleep( $this->sleep );
        }
        else
        {
            // Go to bed till 2am tommorow
            @time_sleep_until( (time() + 86380) );
        }
        
        //-------------------------------------
        // Lets reload ourself to make a loop
        //-------------------------------------
        $this->process();
    }
    
}
?>
Once Again this is just to give you some ideas, I am not saying this is safe to run on your server, you should do some reading up on how to secure it much better and also how much memory/processer this sucker will chew up, I am not gonna do all the work for ya now ;-P


Messages In This Thread
PHP and Queue Systems? - by El Forum - 01-28-2008, 09:07 PM
PHP and Queue Systems? - by El Forum - 01-28-2008, 09:42 PM
PHP and Queue Systems? - by El Forum - 01-28-2008, 09:53 PM
PHP and Queue Systems? - by El Forum - 01-29-2008, 04:02 AM
PHP and Queue Systems? - by El Forum - 01-29-2008, 09:19 AM



Theme © iAndrew 2016 - Forum software by © MyBB