Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Anyone experience with php-resque
  • Anyone ever worked with https://github.com/chrisboulton/php-resque in combination with fuelphp?
  • I understand how to set it up, but is there a way to call fuelphp or include my application into the php resque job?
  • I have never used it, but looking at the examples I don't think that is going to work without modification, as it looks for specific classes.

    Maybe https://bitbucket.org/codeyellow/queue/overview is a better solution?
  • yeah I am also looking at that one... But is it possible to run the oil task as a background service?
  • You'll have to do something custom for that, in the end it's just a class like all others, which you can load and execute.

    Essentially, oil tasks are designed to run from cron of manually from the commandline, so triggered from outside the framework.

    If you have an external (to Fuel) queuing system, you need to be able to queue commandline jobs in order to be able to start oil, and not PHP classes.
  • Been messing around with php-resque (really like it so far). Problem is that the job classes do not understand anything in my FuelPHP app.
    I copied my "oil" file to a boot.php (deleted the last 2 lines, which loads up Oil package).

    Is this a way to go? ORM seems to work and stuff...
  • I can't comment without looking in detail to what you are doing.

    One of my reasons not to use it was exactly this, for every job fired you need to load the entire framework again.

    In the end we decided to turn it around, and have a task that fires the queue worker (which is then a resident process, but running from the framework through oil), the queue worker can then call classes within the application (our modules have a classes/jobs folder for that) that have full framework access.

    We used https://bitbucket.org/codeyellow/queue as a starting point.

    This is how we fire up the queueworker:

    #!/bin/bash
    #
    # Queue manager script, to make sure the required number of worker instances
    # are running. Schedule this in cron to make sure any crashed workers will
    # be restarted.
    #

    # Get the full path to ourselfs
    SCRIPTPATH="$( dirname "$( which "$0" )" )"

    # how many workers do we need to start?
    if [ $# -gt 0 ]; then
        WORKERS=$1
    else
        WORKERS=1;
    fi

    # where does the php binary live?
    PHP=`which php`

    # command that starts the worker
    COMMAND="$SCRIPTPATH/../../../oil refine queueworker"

    # loop to process the worker instantiation
    while :
    do
            # bail out if we have started enough workers
            PROCESS_COUNT=`pgrep -f "$COMMAND" | wc -l`
            if [ $PROCESS_COUNT -eq $WORKERS ]; then
                    exit 0
            fi

            # too many workers running?
            if [ $PROCESS_COUNT -gt $WORKERS ]; then
                # kill a worker off nicely
                PROCESS=`pgrep -f -n "$COMMAND"`
                kill -15 $PROCESS
                sleep 1
            else
                # start a new worker
                $PHP $COMMAND &
            fi
    done

    This script is called from cron every minute, the parameter comes from a file that the application admin can update from the app, so changing it (or disabling all queueworkers) will change the number running within a minute...
  • Ok cool! But what does "oil refine queueworker" do? Is that the same script as this? https://bitbucket.org/codeyellow/queue/src/b8bffc9b79c5c564d6cde4e287c6b87fb2e710e1/tasks/queue.php?at=2.2
  • Our code is a bit different, but the principle is the same, yes.

    It basically checks the queue for a job to run, a job being a static class method with some additional parameters. When a job is found, it's static method is called, so it's executed within the task context setup by oil when it called the run method of the queueworker, which means the method has full access to the framework.
  • How can I execute the queue script (you posted above) with a FUEL_ENV=production variable?

    $PHP $COMMAND &

    But I want "FUEL_ENV=production $PHP $COMMAND &"
    I tried to change the script but it doesn't seem to work...?
  • I needed to set it to this:

    "env FUEL_ENV=production $PHP $COMMAND &"

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion