chrisboulton / php-resque

PHP port of resque (Workers and Queueing)
MIT License
3.43k stars 759 forks source link

Multiple APP_INCLUDE #204

Closed sameg14 closed 8 years ago

sameg14 commented 10 years ago

Currently it does not seem possible to add multiple APP_INCLUDE This should be supported, and they should be separated by "," as such

in bin/resque on line 61

$APP_INCLUDE = getenv('APP_INCLUDE');
if($APP_INCLUDE) {

    //Check to see if this contains a "," i.e. there are multiple include paths
    if (strpos($APP_INCLUDE, ',') !== false) {
        $appIncludeExp = explode(',', $APP_INCLUDE);
        if(!empty($appIncludeExp)){
            foreach($appIncludeExp as $appInclude){
                require_once $appInclude;
            }
        }
    }else{
        if(!file_exists($APP_INCLUDE)) {
            die('APP_INCLUDE ('.$APP_INCLUDE.") does not exist.\n");
        }
        require_once $APP_INCLUDE;
    }
}
danhunsaker commented 10 years ago

I disagree. It's easy to write a wrapper script that handles including other scripts; there's no good reason to support this, as it's only intended to initialize enough logic for jobs to run. It's up to the developer to ensure that script loads everything required.

sameg14 commented 10 years ago

This use case is specifically for Symfony. The only way I can get the jobs to recognize autoloaded classes is to include "both" autoloaders

app/autoload.php
php-resque/vendor/autoload.php

I have forked the repo and made this change, it is non invasive, and if people want to use it all they have to do is something like this

COUNT=20 APP_INCLUDE=/home/vagrant/symfony_project/app/autoload.php,/home/vagrant/php-resque/vendor/autoload.php QUEUE=high nohup php php-resque/bin/resque &

This is the commit fyr https://github.com/sameg14/php-resque/commit/9fe275cecbb5f9de4d484763b0b60f5d8e2f750e

danhunsaker commented 10 years ago

Like I said, it's easy to write a wrapper script that loads everything you need loaded. Your APP_INCLUDE would point to the wrapper script (say, load_autoloaders.php), which in turn loads in both autoloaders. This is the preferred method of using APP_INCLUDE, though the best use case actually avoids APP_INCLUDE altogether by having the wrapper script also include the Resque start script, and then be called directly.