chrisboulton / php-resque

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

Cannot use resque with namespace in Laravel 4.2 #247

Closed tranluan91 closed 9 years ago

tranluan91 commented 9 years ago

When I try use php-resque with Laravel 4.2, it's OK if I didn't use Model in resque I have try

QUEUE=default APP_INCLUDE=app/queues.php php vendor/chrisboulton/php-resque/resque.php

Result:

PHP Fatal error:  Class 'Eloquent' not found in /home/luantv/work/app/models/User.php on line 4
PHP Stack trace:
PHP   1. {main}() /home/luantv/work/vendor/chrisboulton/php-resque/resque.php:0
PHP   2. require_once() /home/luantv/work/vendor/chrisboulton/php-resque/resque.php:32
PHP   3. include() /home/luantv/work/app/queues.php:6

app/queues.php

<?php

include 'models/User.php';
include 'services/BaseService.php';
include 'services/UserService.php';
include 'services/QueueService.php';
include 'services/GcmPushNotificationService.php';

models/Users.php

<?php

class User extends Eloquent
{
    //
}

Please help me! Thanks!

chrisboulton commented 9 years ago

Hi,

The APP_INCLUDE directive should be used to initialize your application in a way that it includes all of the necessary libraries for it to run - in the case of Laravel, this would be something specific to that which just sets up the framework (and includes Eloquent, etc) without trying to handle a web request.

You might be able to use something like this: https://github.com/ellisthedev/laravel-resque - it also seems to provide a console command (https://github.com/ellisthedev/laravel-resque/blob/master/src/Awellis13/Resque/Console/ListenCommand.php) for starting a worker, which you can either use or leverage for inspiration.

tranluan91 commented 9 years ago

@chrisboulton thanks! I need use priorities for queue, so if I use laravel-resque, can I use priorities of PHP-resque?

tranluan91 commented 9 years ago

My solution: app/queues.php

<?php
require __DIR__ . '/../bootstrap/autoload.php';
require_once __DIR__ . '/../bootstrap/start.php';

include 'models/User.php';
include 'services/BaseService.php';
include 'services/UserService.php';
include 'services/QueueService.php';
include 'services/GcmPushNotificationService.php';

And when need call something in model, I run a command of Laravel.