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

cURL error 2: Failed initialization #5631

Open
pifeifei opened this issue Dec 22, 2024 · 1 comment
Open

cURL error 2: Failed initialization #5631

pifeifei opened this issue Dec 22, 2024 · 1 comment

Comments

@pifeifei
Copy link

Please answer these questions before submitting your issue.

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

use GuzzleHttp\Client;
use GuzzleHttp\RequestOptions;
use Swoole\Runtime;

include_once __DIR__.'/vendor/autoload.php';

Runtime::enableCoroutine(); // curl 在这行之后报错

$url = 'https://cn.bing.com/AS/Suggestions?pt=page.serp&bq=%5cSwoole%5cRuntime%3a%3aenableCoroutine+%E4%B9%8B%E5%90%8E+curl+%E6%8A%A5%E9%94%99++&mkt=zh-cn&ds=mobileweb&qry=%5Cswoole%5Cruntime%3A%3Aenablecoroutine%20%E4%B9%8B%E5%90%8E%20curl%20%E6%8A%A5%E9%94%99%20&cp=44&csr=1&msbqf=false&pths=1&cvid=4920C5EFE5BF4F939C7C29FBDDA1B0A5';
$response = (new Client())->get($url);
$json = json_decode($response->getBody()->getContents(), true);

dump($json);
  1. What did you expect to see?
    正常使用,Runtime::enableCoroutine(); 不影响原代码, 不再 run() 中也可以用

  2. What did you see instead?
    cURL error 2: Failed initialization

image
  1. What version of Swoole are you using (show your php --ri swoole)?
  ~ php81 --ri swoole

swoole

Swoole => enabled
Author => Swoole Team <[email protected]>
Version => 5.1.6
Built => Dec 20 2024 15:26:58
coroutine => enabled with boost asm context
kqueue => enabled
rwlock => enabled
sockets => enabled
openssl => OpenSSL 3.4.0 22 Oct 2024
dtls => enabled
http2 => enabled
json => enabled
curl-native => enabled
pcre => enabled
c-ares => 1.34.4
zlib => 1.2.12
brotli => E16781312/D16781312
mysqlnd => enabled
async_redis => enabled
coroutine_pgsql => enabled
coroutine_sqlite => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_fiber_mock => Off => Off
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => On => On
swoole.unixsock_buffer_size => 262144 => 262144
  1. What is your machine environment used (show your uname -a & php -v & gcc -v) ?

Darwin pffmac-4.local 23.4.0 Darwin Kernel Version 23.4.0: Fri Mar 15 00:10:42 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6000 arm64

PHP 8.1.31 (cli) (built: Nov 19 2024 15:24:51) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.31, Copyright (c) Zend Technologies
with Zend OPcache v8.1.31, Copyright (c), by Zend Technologies

Apple clang version 15.0.0 (clang-1500.3.9.4)

@NathanFreeman
Copy link
Member

你执行了Runtime::enableCoroutine();实例化curl就必须在 run() 函数中进行,否则没法依赖事件机制实现协程化。
Runtime::enableCoroutine();执行之后会马上替换相关的curl函数的。

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

No branches or pull requests

2 participants