Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to run multiple workers on one machine like chrisboulton/php-resque using COUNT environment variable? #56

Closed
davidtall opened this issue Aug 29, 2017 · 17 comments

Comments

@davidtall
Copy link
Contributor

No description provided.

@xelan xelan added the Question label Aug 29, 2017
@davidtall
Copy link
Contributor Author

I kown that,run comand "bin/resque worker:start &" many times .Thanks

@francislavoie
Copy link
Contributor

francislavoie commented Aug 30, 2017

I think the way to implement this would be to add logic here: https://github.com/mjphaynes/php-resque/blob/master/src/Resque/Commands/Worker/Start.php#L48 which would fork N times, where N is the value of the COUNT env var, if it's set. If you want to write a PR for that, I'd be happy to review!

@davidtall
Copy link
Contributor Author

thanks,I will do that in my spare time。I have another question, What's the difference between Predis and phpredis? I want to replace Predis into Credis (https://github.com/colinmollenhour/credis) ,a wrapper of phpredis ,beacuse phpredis is a php extension ,I think it can resutl in better performance.

@francislavoie
Copy link
Contributor

francislavoie commented Sep 1, 2017

So, that topic is a bit complicated...

Predis is a php library which facilitates the use of redis. This lib uses Predis because it makes it cleaner to write the code for it. I have a feeling that it was also picked because of some apparent performance issues with Credis that has been seen in the past (see chrisboulton/php-resque#248). It seems that Predis is much more well maintained and current compared to Credis.

Predis works on its own as a pure PHP implementation to interface with a redis instance, but it also supports using php extensions to accelerate itself, if they're available. Predis works best with phpiredis, which is one of the PHP extensions for redis. There's more than one. The other is phpredis. The naming is similar, and therefore confusing.

A little while back when I worked on making changes to this lib, I added support for phpiredis via a config flag. In your config.yml, just make sure you have phpiredis: true under redis:.

See #42 for some info about phpredis support. Currently I don't actually know if Predis works with phpredis, but my hunch is that it doesn't. Because of that, I recommend right now to use phpiredis instead.

Oh also, if you install phpiredis, I'm pretty sure you also need hiredis installed. See the instructions here: https://github.com/nrk/phpiredis

@davidtall
Copy link
Contributor Author

davidtall commented Sep 1, 2017

I set phpiredis: true in config.yml ,then use command "bin/resque woker:start " to start worker,but it is not available.

print_r($config) in Redis __construct ,var phpiredis is none ,
then I add 'phpiredis' => 'redis.phpiredis', into Command.php $configOptionMap,add new InputOption('phpiredis', 'pr', InputOption::VALUE_OPTIONAL, 'enable phpiredis', false), into Command.php funtion mergeDefinitions, in Comand.php initialize, add key 'phpiredis' => $config['phpiredis'], like Resque\Redis::setConfig(array( 'scheme' => $config['scheme'], 'host' => $config['host'], 'port' => $config['port'], 'namespace' => $config['namespace'], 'phpiredis' => $config['phpiredis'], 'password' => $config['password'] ));

then print_r($config) in Redis __construct ,var phpiredis is 1,so it can get correct value from config.yml .

but when I start worker, show error:php: symbol lookup error: /usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/phpiredis.so: undefined symbol: redisReplyReaderCreate
My PHP environment is 7.1,I had installed phpiredis extensions.

@francislavoie
Copy link
Contributor

I use docker, so this is how I install it in on my image (alpine linux):

RUN apk add --no-cache hiredis && \
    apk add --no-cache --virtual .build-deps hiredis-dev && \
    git clone https://github.com/nrk/phpiredis.git && \
    ( \
        cd phpiredis && \
        phpize && ./configure --enable-phpiredis && \
        make && make install && \
        docker-php-ext-enable phpiredis \
    ) && \
    rm -rf phpiredis && \
    apk del .build-deps

@davidtall
Copy link
Contributor Author

so can not get phpiredis value from config.yml is a bug?

@francislavoie
Copy link
Contributor

francislavoie commented Sep 1, 2017

Oh, I think I see what's going on for you. I think you have too recent a version of hiredis installed, which changed some of the function names. See nrk/phpiredis#52

Maybe you should fork phpiredis and make the changes from that PR and try again? I think the alpine release I use has an older version of hiredis, meaning I didn't run into this problem.

Edit: btw, protip, you can use ``` to make code blocks. It's kinda hard to read what you wrote above because you inlined everything

Edit2: Or maybe you didn't install hiredis and hiredis-dev at all? They're required dependencies to build/run phpiredis.

@davidtall
Copy link
Contributor Author

davidtall commented Sep 1, 2017

Oh,I'm sorry ,My english is so pool.I mean if phpiredis extensions is correct ,why it can not get phpiredis value from config.yml before I changed code?
this is my changed code :

print_r($config) in Redis __construct ,var phpiredis is none ,
then I add
'phpiredis' => 'redis.phpiredis',
into Command.php $configOptionMap,add
new InputOption('phpiredis', 'pr', InputOption::VALUE_OPTIONAL, 'enable phpiredis', false),
into Command.php funtion mergeDefinitions,
in Comand.php initialize, add key 'phpiredis' => $config['phpiredis'], like
Resque\Redis::setConfig(array( 'scheme' => $config['scheme'], 'host' => $config['host'], 'port' => $config['port'], 'namespace' => $config['namespace'], 'phpiredis' => $config['phpiredis'], 'password' => $config['password'] ));

Is this a bug ? or beacause I use PHP7.1?

@francislavoie
Copy link
Contributor

francislavoie commented Sep 1, 2017

It feels like your folder structure might be in a way that the lib doesn't find your config.yml file. In my project, I put Resque::loadConfig('config/resque.yml'); at the bottom of my resque command file, just before $application->run();, because I have my file named differently and in a different folder.

The other thing is that Command.php doesn't support phpiredis as an argument right now, I think it's only configurable via config.yml. That's my bad, I didn't realize people would be wanting to configure it that way as well.

Other than that, I'm not entirely sure what's going wrong based on just the information you gave me.

@davidtall
Copy link
Contributor Author

Oh ,I know your mean ,I didn't call Resque::loadConfig() before $application->run() ,so when I run "bin/resque worker:start",It will load default config file,and call function Resque\Redis::setConfig($config) in Command.php function initialize, but the param $config dosen't contain phpiredis var.

so,calling Resque::loadConfig() before $application->run(); can solve my problem.
Thanks!

@davidtall
Copy link
Contributor Author

Are you Canadian?I'm curious now that Canada is at night? 😄

@francislavoie
Copy link
Contributor

Yes. I'm just awake late tonight. 🌔

@xelan
Copy link
Collaborator

xelan commented Jan 5, 2018

How is the current status on this issue? As far as I see, it touches a few topics:

If everything is covered there, I'd close this issue. What do you think @davidtall and @francislavoie?

@xelan
Copy link
Collaborator

xelan commented Jan 15, 2018

For the suggested deployment we should add some documentation for the upcoming release, I think the rest is covered already. Therefore I'm closing this issue. If you think otherwise, just feel free to reopen 😄

@xelan xelan closed this as completed Jan 15, 2018
@francislavoie
Copy link
Contributor

Sorry I never replied, I had sometime typed up last week but I got sidetracked!

Yeah IMO everything is already dealt with. My Dockerfile unfortunately has some closed source stuff in it so I can't really share that fully, but I can provide a snippet for how I'm installing phpiredis. I'll do that in #42 like you asked, when I find a minute 😄

@xelan
Copy link
Collaborator

xelan commented Jan 16, 2018

No problem, I hope you had a good start in the new year nevertheless 😄

Thank you, no problem. I have a Dockerfile example as well which I can integrate.... Will just take a few days, as I'm also quite busy atm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants