wa0x6e / Cake-Resque

Resque plugin for CakePHP : for creating background jobs that can be processed offline later
MIT License
159 stars 56 forks source link

Use custom console handler for stdout #76

Closed mfn closed 2 years ago

mfn commented 9 years ago

The original cake ConsoleHandler uses fopen('php://stdout') which deep down uses the C call 'dup' to duplicate stdout. However this can lead to a worker not returning the shell, e.g.

ssh host .../cake CakeResque.CakeResque start --queue test

would hang without this change.

Fixes kamisama/Cake-Resque#75


Using a custom ConsoleHandler which does not open directly php://stdout was the only way avoiding the dup() call causes the hang when trying to instrument starting workers via ssh.

wa0x6e commented 9 years ago

What are the removed code from __construct() doing ? I understand that using plain text for the output solve the issue, but is it breaking other thing that only php://stdout can do ? Is the output styling (color, bold, etc ..) still functioning ?

mfn commented 9 years ago

What are the removed code from __construct() doing ?

This line from cakes ConsoleOutput, internally in PHP, leads to calling dup() on the stdout fd and this seems to mess up certain beaviour as outlined in https://github.com/kamisama/Cake-Resque/issues/75#issuecomment-64819153

It's a tricky technicality I cannot explain yet.

I understand that using plain text for the output solve the issue, but is it breaking other thing that only php://stdout can do ?

I'm not aware of any breakage. All the code does it avoid fopen on stdout. If you look through the ConsoleOutput class, the internal property $this->_output is only used in the constructor and the _write() method and my extending class handles this.

Is the output styling (color, bold, etc ..) still functioning ?

Yes, it still works for me.

There's not difference between writing to the stdout file handle or using echo. The intention of ConsoleOutput is to be flexible so that it could either be stdout, stderr or a file which isn't otherwise interchangeable with echo. The new CakeResqueEchoConsoleOutput class is only suitable for stdout and thus only this class is passed to the Shell constructor:

parent::__construct(new CakeResqueEchoConsoleOutput());
mfn commented 2 years ago

Closing, no longer using CakeResque