Skip to content

Unable to cast curl_init to int in >=4.5.4 #3883

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

Closed
grizzm0 opened this issue Nov 26, 2020 · 9 comments
Closed

Unable to cast curl_init to int in >=4.5.4 #3883

grizzm0 opened this issue Nov 26, 2020 · 9 comments
Labels

Comments

@grizzm0
Copy link

grizzm0 commented Nov 26, 2020

  1. What did you do? If possible, provide a simple script for reproducing the error.

I've got a dependency on ezimuel/ringphp which casts curl_init() to an int (see here).

This was working fine in swoole <=4.5.3 but stopped working with swoole >=4.5.4.

  1. What did you expect to see?

  2. What did you see instead?

ErrorException (E_NOTICE)
Object of class Swoole\Curl\Handler could not be converted to int
  1. What version of Swoole are you using (show your php --ri swoole)?
swoole

Swoole => enabled
Author => Swoole Team <[email protected]>
Version => 4.5.4
Built => Nov 26 2020 07:16:59
coroutine => enabled
epoll => enabled
eventfd => enabled
signalfd => enabled
spinlock => enabled
rwlock => enabled
zlib => 1.2.11
mutex_timedlock => enabled
pthread_barrier => enabled
async_redis => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => On => On
swoole.unixsock_buffer_size => 8388608 => 8388608
  1. What is your machine environment used (show your uname -a & php -v & gcc -v) ?
Linux 525268495fb3 5.4.39-linuxkit #1 SMP Fri May 8 23:03:06 UTC 2020 x86_64 Linux
PHP 7.4.12 (cli) (built: Nov  5 2020 20:41:34) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
@sy-records
Copy link
Member

Object of class Swoole\Curl\Handler could not be converted to int

This is a known problem with Hook Curl, SWOOLE_HOOK_CURL is switched on by default from v4.5.4 onwards, You can manually switch off to resolve the problem.

Co::set(['hook_flags'=> SWOOLE_HOOK_ALL ^ SWOOLE_HOOK_CURL]);

@sy-records
Copy link
Member

sy-records commented Nov 27, 2020

@grizzm0 Are there any questions? You can replace guzzle's handler to use Coroutine.

It is a Notice error, you can also ignore it

PHP Notice:  Object of class Swoole\Curl\Handler could not be converted to int 

or

composer require sy-records/ringphp

I forked it to fix the problem, see lufei/ringphp@1eb3dbb

@grizzm0
Copy link
Author

grizzm0 commented Nov 27, 2020

Thanks @sy-records

It's a third party dependency of elastic/elasticsearch-php though and I'd rather not override the dependency.
Seems like they'll replace the HTTP transport in a future release here elastic/elasticsearch-php#1028

I guess I'll just have to stay on an older version or disable SWOOLE_HOOK_CURL in mezzio/mezzio-swoole for now.

If this is not fixable in swoole itself we can close the issue.

@sy-records
Copy link
Member

It should be these components that go on to modify the code, and in PHP8, curl is not a resource type anymore.

@CuongPhi
Copy link

Please help me fix this bug in mezzio/mezzio-swoole
Many thanks!

@grizzm0
Copy link
Author

grizzm0 commented Mar 26, 2021

Please help me fix this bug in mezzio/mezzio-swoole
Many thanks!

<?php

declare(strict_types=1);

namespace Core;

use Swoole\Http\Server as SwooleHttpServer;

final class ConfigProvider
{
    public function __invoke(): array
    {
        return [
            'dependencies' => $this->getDependencies(),
        ];
    }

    private function getDependencies(): array
    {
        return [
            'delegators' => [
                SwooleHttpServer::class => [
                    Factory\Delegator\SwooleHttpServerDelegatorFactory::class,
                ],
            ],
        ];
    }
}
<?php

declare(strict_types=1);

namespace Core\Factory\Delegator;

use Interop\Container\ContainerInterface;
use Laminas\ServiceManager\Factory\DelegatorFactoryInterface;
use Swoole\Http\Server;

use const SWOOLE_HOOK_ALL;
use const SWOOLE_HOOK_CURL;

final class SwooleHttpServerDelegatorFactory implements DelegatorFactoryInterface
{
    public function __invoke(ContainerInterface $container, $name, callable $callback, ?array $options = null): Server
    {
        /** @var Server $swooleHttpServer */
        $swooleHttpServer = $callback();
        $swooleHttpServer->set([
            'hook_flags' => SWOOLE_HOOK_ALL ^ SWOOLE_HOOK_CURL,
        ]);

        return $swooleHttpServer;
    }
}

@grizzm0
Copy link
Author

grizzm0 commented Mar 26, 2021

hook_flags needs to be in the options array.

Didn't know the options was exposed like that. Thanks. In that case there's no need for my delegator.

@CuongPhi
Copy link

I got it. I will try this. Thank you!
I deleted image attach because of policy.

@babarinde
Copy link

hook_flags needs to be in the options array.

Didn't know the options was exposed like that. Thanks. In that case there's no need for my delegator.

+1

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

No branches or pull requests

4 participants