Replaced all invocations to strlen and substr (Fix #6) #5

Closed
wants to merge 2 commits into
from

Projects

None yet

4 participants

@Astrac
Astrac commented Jan 16, 2012

This modifications are to make the library compatible with environments in which php has been configured to override string functions with the correspondent mb_string ones (i.e. to force the internal encoding to UTF-8).

@videlalvaro
Collaborator

Do you think there would be any impact for library users that for some reason don't have the setup you have?

The library already uses the mb_* functions so that shouldn't be a problem, but anyway, I have to ask.

@Astrac
Astrac commented Jan 16, 2012

I don't think there will be any problem for other people: the default behavior of strlen and substr function is to work with ASCII encoding, with my pull request I'm just forcing the usage of the ASCII encoding when dealing with binary data even in environment such as mine (where we overload strlen and substr to use a multibyte encoding and break the correspondence between bytes and chars).

@orensol orensol referenced this pull request Jan 1, 2013
Closed

Exception when running demo #55

@akandels akandels added a commit to akandels/php-amqplib that referenced this pull request Oct 29, 2013
@akandels akandels hotfix: continue instead of break from while if fread returns an empt…
…y string

Introduced in 461961f

Breaking from the loop is causing the following exception:

    Consumer failure PhpAmqpLib\Exception\AMQPRuntimeException Exception 'Error reading data. Received 0 instead of expected 7 bytes':
    #0 /my/path/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/AMQPReader.php(128): PhpAmqpLib\Wire\IO\StreamIO->read(7)
    #1 /my/path/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/AMQPReader.php(88): PhpAmqpLib\Wire\AMQPReader->rawread(7)
    #2 /my/path/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(311): PhpAmqpLib\Wire\AMQPReader->read(7)
    #3 /my/path/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(344): PhpAmqpLib\Connection\AbstractConnection->wait_frame(0)
    #4 /my/path/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Channel/AbstractChannel.php(121): PhpAmqpLib\Connection\AbstractConnection->wait_channel(1, 0)
    #5 /my/path/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Channel/AbstractChannel.php(229): PhpAmqpLib\Channel\AbstractChannel->next_frame(0)

I believe because a string can be a valid data block transferred in and of itself. Merely continuing instead of breaking until the feof() fixes the problem on my version of Rabbit:

RabbitMQ 3.1.5, Erlang R14B04
b56758f
@akandels akandels added a commit to akandels/php-amqplib that referenced this pull request Oct 29, 2013
@akandels akandels hotfix: continue instead of break from while if fread returns an empt…
…y string

Introduced in 461961f

Breaking from the loop is causing the following exception:

    Consumer failure PhpAmqpLib\Exception\AMQPRuntimeException Exception 'Error reading data. Received 0 instead of expected 7 bytes':
    #0 /my/path/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/AMQPReader.php(128): PhpAmqpLib\Wire\IO\StreamIO->read(7)
    #1 /my/path/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/AMQPReader.php(88): PhpAmqpLib\Wire\AMQPReader->rawread(7)
    #2 /my/path/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(311): PhpAmqpLib\Wire\AMQPReader->read(7)
    #3 /my/path/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(344): PhpAmqpLib\Connection\AbstractConnection->wait_frame(0)
    #4 /my/path/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Channel/AbstractChannel.php(121): PhpAmqpLib\Connection\AbstractConnection->wait_channel(1, 0)
    #5 /my/path/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Channel/AbstractChannel.php(229): PhpAmqpLib\Channel\AbstractChannel->next_frame(0)

I believe because a string can be a valid data block transferred in and of itself. Merely continuing instead of breaking until the feof() fixes the problem on my version of Rabbit:

RabbitMQ 3.1.5, Erlang R14B04
2a08bb1
@akandels akandels added a commit to akandels/php-amqplib that referenced this pull request Oct 30, 2013
@akandels akandels hotfix: alternative fix for "Error reading data. Received 0 instead o…
…f expected 7 bytes"

For the following error:

    Consumer failure PhpAmqpLib\Exception\AMQPRuntimeException Exception 'Error reading data. Received 0 instead of expected 7 bytes':
    #0 /my/path/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/AMQPReader.php(128): PhpAmqpLib\Wire\IO\StreamIO->read(7)
    #1 /my/path/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/AMQPReader.php(88): PhpAmqpLib\Wire\AMQPReader->rawread(7)
    #2 /my/path/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(311): PhpAmqpLib\Wire\AMQPReader->read(7)
    #3 /my/path/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(344): PhpAmqpLib\Connection\AbstractConnection->wait_frame(0)
    #4 /my/path/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Channel/AbstractChannel.php(121): PhpAmqpLib\Connection\AbstractConnection->wait_channel(1, 0)
    #5 /my/path/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Channel/AbstractChannel.php(229): PhpAmqpLib\Channel\AbstractChannel->next_frame(0)

I have another pull request at php-amqplib#119 which reverses the 461961f commit but fixes the problem for me.

This also fixes the problem for me as an alternative without having to reverse that commit.
9b72c1d
@eladeon
eladeon commented Apr 8, 2014

I seem to have the same problem in our environment. As mentioned in the post above, overriding the mbstring function to UTF-8 in your php.ini file for example taking the following settings will break this library:

mbstring.detect_order => auto => auto
mbstring.encoding_translation => On => On
mbstring.func_overload => 6 => 6
mbstring.http_input => auto => auto
mbstring.http_output => UTF-8 => UTF-8
mbstring.http_output_conv_mimetypes => ^(text/|application/xhtml+xml) => ^(text/|application/xhtml+xml)
mbstring.internal_encoding => UTF-8 => UTF-8
mbstring.language => Neutral => Neutral
mbstring.strict_detection => Off => Off
mbstring.substitute_character => no value => no value

You will then get errors such as:

PhpAmqpLib\Exception\AMQPRuntimeException = Error reading data. Received 26 instead of expected 27 bytes
PhpAmqpLib\Exception\AMQPRuntimeException = Error reading data. Received 222 instead of expected 223 bytes

@eladeon
eladeon commented Apr 8, 2014

Unfortunately this "pull" branch is extremely out of date with the master branch. I have now made the same kind of changes locally and its working on some messages, but I obviously have a bug and it seems to be failing on publishing larger messages with a new error. Are there any plans to replicate these changes on the master code-base? I have tried the pecl amqp C extension as well, and it doesn't have the same issue (although it doesn't offer a socket time-out on the blocking consume which this client do, which I why I would prefer to use this client)

@videlalvaro
Collaborator

I don't have plans on doing this work myself. If you want to suggest a PR I would welcome it.

@fprochazka
Contributor

Is this still relevant? I think it should be closed, as the mb_ functions are already used in master.

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