Giter VIP home page Giter VIP logo

Comments (13)

rybakit avatar rybakit commented on August 30, 2024

What happens if you run examples/protocol/execute.php? Or try first with $client->ping() and check if it succeeds.

from client.

mikkiek avatar mikkiek commented on August 30, 2024

@rybakit

Sadly $client->ping() doesn't work too.
PHP
[Tarantool\Client\Exception\RequestFailed]
lid MsgPack - packet body (20)
Tarantool
2019-05-31 11:57:17.550 [1] iproto xrow.c:174 E> ER_INVALID_MSGPACK: Invalid MsgPack - packet body
2019-05-31 11:57:43.571 [1] iproto xrow.c:174 E> ER_INVALID_MSGPACK: Invalid MsgPack - packet body

from client.

rybakit avatar rybakit commented on August 30, 2024

Hmm, all client tests pass on all supported Tarantool versions, including the latest 2.2.0: https://travis-ci.org/tarantool-php/client/jobs/539337099#L878. This makes me think that something is misconfigured on your side. Could you show your init lua script or, ideally, provide a full reproducer including a dockerfile (or/and docker-compose), php and lua scripts?

from client.

mikkiek avatar mikkiek commented on August 30, 2024

Not sure if it could help and easy to use, but i've published my docker-compose and all related files to https://github.com/mikkiek/tarantool-php-issue-55
As you can see, i'm using default tarantool 2.2.0, though php-fpm based on default image but has a lot additional modules

from client.

rybakit avatar rybakit commented on August 30, 2024

I was able to reproduce the error using your docker-compose. The problem is with the mbstring.func_overload = 2 setting in /usr/local/etc/php/php.ini. When you disable this line or run your script in cli mode with the -n flag, everything just works. Note that mbstring function overloading is deprecated as of PHP 7.2.0.

from client.

mikkiek avatar mikkiek commented on August 30, 2024

Thank you for answer. I will think what can i do with it (mbstring.func_overload hardly can effect on it)
And last question: Does exist any way to run your code with mbstring.func_overload = 2?
Thank you!

from client.

rybakit avatar rybakit commented on August 30, 2024

Does exist any way to run your code with mbstring.func_overload = 2?

You may try creating a packer which will de-activate this setting while packing/unpacking packets (not tested):

final class MbstringOverloadedPacker implements Packer
{
    private $packer;
    
    public function __construct(Packer $packer)
    {
        $this->packer = $packer;
    }
 
    public function pack(Request $request, ?int $sync = null) : string
    {
        $funcOverload = ini_get('mbstring.func_overload');
        ini_set('mbstring.func_overload', 0);

        try {
            return $this->packer->pack($request, $sync);
        } finally {
            ini_set('mbstring.func_overload', $funcOverload);
        }
    }

    public function unpack(string $data) : Response
    {
        $funcOverload = ini_get('mbstring.func_overload');
        ini_set('mbstring.func_overload', 0);

        try {
            return $this->packer->unpack($data);
        } finally {
            ini_set('mbstring.func_overload', $funcOverload);
        }
    }
}

And then wrap a regular packer and build a client object from scratch:

$packer = new MbstringOverloadedPacker(new PurePacker());
...
$handler = new DefaultHandler($connection, $packer);
$client = new Client($handler);
$client = $client->withMiddleware(new AuthMiddleware('<username>', '<password>'));

from client.

mikkiek avatar mikkiek commented on August 30, 2024

Hello,

Unfortunatelly, the 'mbstring.func_overload' setting impossible to set in a PHP code.
However, I've found a workaround playing with \mb_internal_encoding('8bit'); for pack\unpack. Also a small change required inside of Greeting class:
$salt = \substr($salt, 0, 20);
replace with
$salt = \mb_substr($salt, 0, 20, '8bit');
And then it start working, anyway partially...

For example:

$result = $client->evaluate('return box.info.memory()');
var_dump($result);

Returns:

array(1) {
[0]=>
array(6) {
["cache"]=>
int(0)
["data"]=>
int(8576)
["tx"]=>
int(0)
["lua"]=>
int(1314007)
["net"]=>
int(933888)
["index"]=>
int(1097728)
}
}

However, the following code:

$result = $client->executeUpdate('
    CREATE TABLE users ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "email" VARCHAR(255))
');
var_dump($result);

Throws an error

[Tarantool\Client\Exception\CommunicationFailed]
Unable to read response length. (0)

It happends for me in both cases mbstring.func_overload = 2 and mbstring.func_overload = 0 . Don't you have any thoughts what else should i check?

Thank you!

from client.

rybakit avatar rybakit commented on August 30, 2024

It happends for me in both cases mbstring.func_overload = 2 and mbstring.func_overload = 0 . Don't you have any thoughts what else should i check?

Does it work if you execute this query in lua console? Try

docker exec -it <your-tarantool-container-id> sh
tarantoolctl connect 3301

and then follow this tutorial: https://www.tarantool.io/en/doc/2.1/tutorials/sql_tutorial/. Also, you could try to test it on Tarantool 2.1. I could debug it as well, but seems like you've already deleted your repo :)

from client.

mikkiek avatar mikkiek commented on August 30, 2024

Does it work if you execute this query in lua console? Try

It's works without any issues in console. I will try to debug a little bit, maybe i've missed string manupulations without 8bit encoding.

I could debug it as well, but seems like you've already deleted your repo :)

Yes, sorry. It's just for internal use. I'm not sure I can publish it, but at the same time I want to solve issues on our projects.

I will back when I find something.

from client.

mikkiek avatar mikkiek commented on August 30, 2024

Thank you for you help.
It works not with Tarantool 2.1.2, 2.2.0 somehow doesn't work, i'll investigate it later.
At the moment I have last question: Don't you have a plan to add for Tarantool\Client\Connection\StreamConnection option which will handle custom Greeting class\object?
Coz' of "mbstring.func_overload" i should change your original file, i dind't find a way around.

from client.

rybakit avatar rybakit commented on August 30, 2024

No, I don't plan to expose the Greeting class and would strongly recommend you to disable the function overloading as it will break every second library you have installed and will not work with the next versions of PHP anyway.

from client.

mikkiek avatar mikkiek commented on August 30, 2024

Unfortunately, I don't have a choice. CMS which is used on a project has requirement mbstring.func_overload = 2

from client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.