Giter VIP home page Giter VIP logo

library's Introduction

Swoole Library

Twitter Discord Library Status License

Dockerized Local Development

First, run one of the following commands to install development packages using Composer:

docker run --rm -v "$(pwd)":/var/www -ti phpswoole/swoole composer update -n

# or, use the official Composer Docker image:
docker run --rm -v "$(pwd)":/app -ti composer update -n --ignore-platform-reqs

# or, use the local Composer if installed:
composer update -n --ignore-platform-reqs

Next, you need to start Docker containers:

docker compose up -d

Alternatively, if you need to rebuild some Docker image and to restart the containers:

docker compose build --progress plain --no-cache
docker compose up -d --force-recreate

Now you can create a bash session in the app container:

docker compose exec app bash

And run commands inside the container:

composer test

Or you can run commands directly inside the app container:

docker compose exec app composer test

Examples

Once you have Docker containers started (as discussed in previous section), you can use commands like following to run examples under folder examples.

Examples of Database Connection Pool

docker compose exec app php examples/mysqli/base.php
docker compose exec app php examples/pdo/base.php
docker compose exec app php examples/redis/base.php

Examples of FastCGI Calls

There is a fantastic example showing how to use Swoole as a proxy to serve a WordPress website using PHP-FPM. Just open URL http://127.0.0.1 in the browser and check what you see there. Source code of the example can be found here.

Here are some more examples to make FastCGI calls to PHP-FPM:

docker compose exec app php examples/fastcgi/greeter/call.php
docker compose exec app php examples/fastcgi/greeter/client.php
docker compose exec app php examples/fastcgi/proxy/base.php
docker compose exec app php examples/fastcgi/var/client.php

Third Party Libraries

Here are all the third party libraries used in this project:

You can find the licensing information of these third party libraries here.

License

This project follows the Apache 2 license.

library's People

Contributors

appla avatar deminy avatar devzer0x00 avatar djw1028769140 avatar doubaokun avatar fakharksa avatar filakhtov avatar huanghantao avatar jcheron avatar kingizzzy avatar landso avatar lbbniu avatar leocavalcante avatar matyhtf avatar maxiaozhi avatar nathanfreeman avatar nhzex avatar shiguangqi avatar sinute avatar sy-records avatar twose avatar yespire avatar yunbaoi avatar yurunsoft avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

library's Issues

help ~~

运行 php base.php 报如下错:
PHP Fatal error: Uncaught PDOException: SQLSTATE[08006] [7] invalid connection option "charset" in @swoole-src/library/core/Database/PDOPool.php:44
Stack trace:
#0 @swoole-src/library/core/Database/PDOPool.php(44): PDO->__construct('pgsql:host=xxxx...', 'xxx', 'xxxx', Array)
#1 @swoole-src/library/core/Database/PDOProxy.php(41): Swoole\Database\PDOPool->Swoole\Database{closure}()
#2 @swoole-src/library/core/ConnectionPool.php(89): Swoole\Database\PDOProxy->__construct(Object(Closure))
#3 @swoole-src/library/core/ConnectionPool.php(58): Swoole\ConnectionPool->make()
#4 /mnt/d/code/wwwroot/swool_library/examples/pdo/base.php(40): Swoole\ConnectionPool->get()
#5 {main}
thrown in @swoole-src/library/core/Database/PDOPool.php on line 44

base.php 里
加上配置 ->withDriver('pgsql'),
注释掉 ->withCharset('utf8mb4')

PDOPool.php里
注释掉 -"charset={$this->config->getCharset()}"
仍报上边的错误...

php --ri swoole

swoole

Swoole => enabled
Author => Swoole Team [email protected]
Version => 4.4.19
Built => Sep 29 2020 15:54:47
coroutine => enabled
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
pcre => enabled
zlib => 1.2.7
mutex_timedlock => enabled
pthread_barrier => enabled
futex => 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

php -v
PHP 7.2.24 (cli) (built: Apr 19 2020 01:32:45) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

php -m | grep pdo
pdo_mysql
pdo_pgsql
pdo_sqlite

FastCGI Proxy Error

php

$documentRoot = base_path('public');
        if (!$documentRoot || !is_dir($documentRoot)) {
            throw new \InvalidArgumentException('Invalid document root');
        }
        $server = new Server('127.0.0.1', 8009, SWOOLE_BASE);
        $server->set([
            'worker_num' => swoole_cpu_num(),
            'http_parse_cookie' => false,
            'http_parse_post' => false,
            'document_root' => $documentRoot,
            'enable_static_handler' => true,
            'static_handler_locations' => ['/'],
        ]);
        $proxy = new Proxy('127.0.0.1:8000', $documentRoot);
        $server->on('request', function (Request $request, Response $response) use ($proxy) {
            $proxy->pass($request, $response);
        });
        $server->start();

error

Fatal error: Uncaught Swoole\Coroutine\FastCGI\Client\Exception: Connection reset by peer in /Users/code/base-api/library/src/core/Coroutine/FastCGI/Client.php:175
Stack trace:
#0 /Users/code/base-api/library/src/core/Coroutine/FastCGI/Client.php(100): Swoole\Coroutine\FastCGI\Client->ioException(54)
#1 /Users/code/base-api/library/src/core/Coroutine/FastCGI/Proxy.php(183): Swoole\Coroutine\FastCGI\Client->execute(Object(Swoole\FastCGI\HttpRequest), -1)
#2 /Users/code/base-api/app/Console/Commands/SwooleCommand.php(82): Swoole\Coroutine\FastCGI\Proxy->pass(NULL, Object(Swoole\Http\Response))
#3 {main}  thrown in /Users/code/base-api/library/src/core/Coroutine/FastCGI/Client.php on line 175In Client.php line 175:
Uncaught Swoole\Coroutine\FastCGI\Client\Exception: Connection reset by peer in /Users/code/base-api/library/src/core/Coroutine/FastCGI/Client.php:175
  Stack trace:
  #0 /Users/code/base-api/library/src/core/Coroutine/FastCGI/Client.php(100): Swoole\Coroutine\FastCGI\Client->ioException(54)
  #1 /Users/code/base-api/library/src/core/Coroutine/FastCGI/Proxy.php(183): Swoole\Coroutine\FastCGI\Client->execute(Object(Swoole\FastCGI\HttpRequest), -1)
  #2 /Users/code/base-api/app/Console/Commands/SwooleCommand.php(82): Swoole\Coroutine\FastCGI\Proxy->pass(NULL, Object(Swoole\Http\Response))
[2020-04-27 10:25:45 *62588.3]	ERROR	php_swoole_server_rshutdown (ERRNO 503): Fatal error: Uncaught Swoole\Coroutine\FastCGI\Client\Exception: Connection reset by peer in /Users/code/base-api/library/src/core/Coroutine/FastCGI/Client.php:175

Roadmap: Swoole Library 5.2

Changed

  • Refactor method \Swoole\Database\PDOStatementProxy::setFetchMode().
  • Refactor method \Swoole\MultibyteStringObject::substr().
  • Refactor method \Swoole\FastCGI\Message::withBody() from public function withBody($body): self; to public function withBody(string|\Stringable $body): self;.
  • Fix method \Swoole\MultibyteStringObject::chunk(), and update the parent method if needed.

Miscellaneous

  • Errors ignored by PHPStan (check file ./phpstan.neon.dist for details)

Is it possible to create a PDOProxy object from an existing PDO connection?

As you can guess, I am trying to integrate an existing db framework into some Swoole based framework in a very lazy and hacky way. I tried new PDOProxy($existingPDO) in a hurry but of course it didn't work. It says it needs a callable but I couldn't figure out what kind callable it's talking about.

That existing PDO was already pulled from the connection pool and I got the real PDO object using the __getObject() method of the PDOProxy class. What I'm trying to do is to put that real pdo back to the pool converting to a PDOProxy object in some separate place of the code.

Exception on PDOStatementProxy+fetch

Call fetch on PDOStatementProxy when there is no result in db throws PDOException instead of returning value(false).

$pdo = new PDO('mysql:host=localhost;dbname=', '', '');
$stmt = $pdo->query('SELECT id FROM user WHERE 1=0');   
$result = $stmt->fetch();   
var_dump($result);
$pdoProxy = new \Swoole\Database\PDOProxy(function() {   
   return new PDO('mysql:host=localhost;dbname=', '', '');   
});
$stmt = $pdoProxy->query('SELECT id FROM user WHERE 1=0');   
$result2 = $stmt->fetch();
var_dump($result2);

Some external dependencies still?

Swoole\ConnectionPool creates a new instance of Swoole\Coroutine\Channel which doesn't exist in the project.

Same goes for Swoole\Coroutine\Server which uses the non-existent class Swoole\Coroutine\Socket.

And the same goes for Swoole\Coroutine\Http\Client.

I discovered this with Psalm (but you could use PHPStan or Phan to find the same).

PDOStatementProxy: fetch mode doesn't allow any extra arguments

$stmt->setFetchMode(PDO::FETCH_NUM);
Using setFetchMode with only 1 argument causes the following warning:

Warning: PDOStatement::setFetchMode(): SQLSTATE[HY000]: General error: fetch mode doesn't allow any extra arguments in @swoole-src/library/core/Database/PDOStatementProxy.php on line 48

setFetchMode doesnt support null as second/third argument.
The assignment of $classNameObject and $ctorarfg should be checked to make the proper call of setFetchMode on $this->__object

public function setFetchMode(int $mode, $classNameObject = null, array $ctorarfg = []): bool
{
$this->setFetchModeContext = [$mode, $classNameObject, $ctorarfg];
return $this->__object->setFetchMode($mode, $classNameObject, $ctorarfg);
}

CURLOPT_UNIX_SOCKET_PATH is not supported

This part with curl hooks enabled:

 \curl_setopt($ch, CURLOPT_UNIX_SOCKET_PATH, '/var/run/docker.sock');

results into following error message:

Fatal error: Uncaught Swoole\Curl\Exception: swoole_curl_setopt(): option[10231] is not supported in @swoole-src/library/core/Curl/Handler.php:655

Is there a chance that this can be implemented?

Question: Pretty permalinks example?

In Apache we have

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

and in NGINX we have try_files $uri $uri/ /index.php?$args;.

What is the appropriate example with Swoole Proxy to support such behavior?

Docker image does not build

I have tried to test the library and go the following output (I will beautify it a bit for readability purposes):

$ docker-compose up
Building app
Step 1/2 : FROM phpswoole/swoole
 ---> 5435a480e26f
Step 2/2 : RUN     
pecl update-channels        
&&     pecl install redis-5.2.1    
&&     docker-php-ext-enable redis 
&&     docker-php-ext-install mysqli pdo_mysql 
&&     echo "swoole.enable_library=off" >> /usr/local/etc/php/conf.d/docker-php-ext-swoole.ini 
&&     {         
echo '[supervisord]';         
echo 'user = root';         echo '';         
echo '[program:wordpress]';         
echo 'command = php /var/www/examples/fastcgi/proxy/wordpress.php';         
echo 'user = root';         
echo 'autostart = true';         
echo 'stdout_logfile=/proc/self/fd/1';         
echo 'stdout_logfile_maxbytes=0';         
echo 'stderr_logfile=/proc/self/fd/1';         
echo 'stderr_logfile_maxbytes=0';     } > /etc/supervisor/service.d/wordpress.conf
 ---> Running in 720d70847ea1
ERROR: Service 'app' failed to build: no status provided on response: unknown

Is this behavior normal?

Barrier类修改

以下情况下不会抛出协程错误异常,正常执行

  • 执行的任务中没有发生协程切换
  • 执行任务列表为空,没有任务

修改后的类

use Swoole\Coroutine;
use Swoole\Exception;
use Swoole\Timer;

class Barrier
{
    private $cid = -1;

    private $timer = -1;

    private static $cancel_list = [];

    public function __destruct()
    {
        if ($this->timer != -1) {
            Timer::clear($this->timer);
            if (static::$cancel_list[$this->cid]) {
                unset(static::$cancel_list[$this->cid]);
                return;
            }
        }

        if ($this->cid != -1 && $this->cid != Coroutine::getCid()) {
            Coroutine::resume($this->cid);
        }else{
            self::$cancel_list[$this->cid] = true;
        }
    }

    public static function make()
    {
        return new static();
    }

    /**
     * @throws Exception
     */
    public static function wait(Barrier &$barrier, float $timeout = -1)
    {
        if ($barrier->cid != -1) {
            throw new Exception('The barrier is waiting, cannot wait again.');
        }
        $cid = Coroutine::getCid();
        $barrier->cid = $cid;
        if ($timeout > 0 && ($timeout_ms = intval($timeout * 1000)) > 0) {
            $barrier->timer = Timer::after($timeout_ms, function () use ($cid) {
                self::$cancel_list[$cid] = true;
                Coroutine::resume($cid);
            });
        }
        $barrier = null;
        (!(self::$cancel_list[$cid] ?? false)) && Coroutine::yield();
    }
}

PDOStatement::bindParam() expects parameter 1 to be string

I am used to coding:

$sql = 'select name from user_account where email=?';
$stmt = $db->prepare($sql);
$stmt->bindParam(1, $email, PDO::PARAM_STR);

But it's throwing an exception:

PDOStatement->bindParam() @swoole-src/library/core/Database/PDOStatementProxy.php:138
PHP TypeError:  PDOStatement::bindParam() expects parameter 1 to be string, int given in @swoole-src/library/core/Database/PDOStatementProxy.php on line 138

I suspect that __object in abstract class is the cause. Another way is working fine:

$sql = 'select name from user_account where email=:email';
$stmt = $db->prepare($sql);
$stmt->bindValue('email', $email, PDO::PARAM_STR);

I'm using the following swoole:

$ php --ri swoole

swoole

Swoole => enabled
Author => Swoole Team <[email protected]>
Version => 4.6.7
Built => Jul 14 2021 09:18:38
coroutine => enabled with boost asm context
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
pcre => enabled
zlib => 1.2.11
mutex_timedlock => enabled
pthread_barrier => enabled
futex => 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

Thank you.

RedisPool跑不了

https://github.com/swoole/library/blob/master/examples/redis/base.php
这个代码跑不了,报错如下:

PHP Fatal error: Uncaught ArgumentCountError: Redis::connect() expects at most 5 parameters, 6 given in @swoole-src/library/core/Database/RedisPool.php:29

php --ri 'swoole'

swoole

Swoole => enabled
Author => Swoole Team [email protected]
Version => 4.4.13RC1
Built => Dec 8 2019 02:25:14
coroutine => enabled
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
openssl => OpenSSL 1.0.2l 25 May 2017
pcre => enabled
zlib => 1.2.8
mutex_timedlock => enabled
pthread_barrier => enabled
futex => 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

For Postgres PDO Connection Pool, the "charset" option gives error.

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

//const POSTGRES_SERVER_DRIVER = 'pgsql'; // I get warning "Already defined" if i uncomment it
const POSTGRES_SERVER_HOST = 'localhost';
const POSTGRES_SERVER_PORT = 5432;
const POSTGRES_SERVER_DB = 'swooledb';
const POSTGRES_SERVER_USER = 'postgres';
const POSTGRES_SERVER_PWD = 'passwd123';

function create_db_connection_pool() {
    return new PDOPool(
            (new PDOConfig())
                ->withDriver(POSTGRES_SERVER_DRIVER)
                ->withHost(POSTGRES_SERVER_HOST)
                ->withPort(POSTGRES_SERVER_PORT)
                // ->withUnixSocket('/tmp/mysql.sock')
                ->withDbName(POSTGRES_SERVER_DB)
                //->withCharset('utf8mb4')
                ->withUsername(POSTGRES_SERVER_USER)
                ->withPassword(POSTGRES_SERVER_PWD)
        );
}

Also, tried ...

->withCharset('utf8mb4')

And, from inside a class, i make call to "create_db_connection_pool()" funtion:

include(db_connection_pool.php);

protected $conn_pool_swoole;

$this->conn_pool_swoole = create_db_connection_pool();
$pgsql_conn_swoole = $this->conn_pool_swoole->get();
  1. What did you expect to see?
Creation of connection pool without any Fatal Error

  1. What did you see instead?
PHP Fatal error:  Uncaught PDOException: SQLSTATE[HY000] [1698] Access denied for user 'postgres'@'localhost' in @swoole-src/library/core/Database/PDOPool.php:44
Stack trace:
#0 @swoole-src/library/core/Database/PDOPool.php(44): PDO->__construct()
#1 @swoole-src/library/core/Database/PDOProxy.php(41): Swoole\Database\PDOPool->Swoole\Database\{closure}()
#2 @swoole-src/library/core/ConnectionPool.php(89): Swoole\Database\PDOProxy->__construct()
#3 @swoole-src/library/core/ConnectionPool.php(58): Swoole\ConnectionPool->make()
#4 /var/www/html/swoole-prac/sw_service.php(160): Swoole\ConnectionPool->get()
#5 [internal function]: sw_service->{closure}()
#6 {main}
  thrown in @swoole-src/library/core/Database/PDOPool.php on line 44

And when used ->withCharset(''), the error became:

PHP Fatal error:  Uncaught PDOException: SQLSTATE[08006] [7] invalid connection option "charset" in @swoole-src/library/core/Database/PDOPool.php:44
Stack trace:
#0 @swoole-src/library/core/Database/PDOPool.php(44): PDO->__construct()
#1 @swoole-src/library/core/Database/PDOProxy.php(41): Swoole\Database\PDOPool->Swoole\Database\{closure}()
#2 @swoole-src/library/core/ConnectionPool.php(89): Swoole\Database\PDOProxy->__construct()
#3 @swoole-src/library/core/ConnectionPool.php(58): Swoole\ConnectionPool->make()
#4 /var/www/html/swoole-prac/sw_service.php(160): Swoole\ConnectionPool->get()
#5 [internal function]: sw_service->{closure}()
#6 {main}
  thrown in @swoole-src/library/core/Database/PDOPool.php on line 44

I can connect postgres using same credentials and using open-smf package for connection pool for swoole.

I suspect that the issue is in the definition of dsn string in constructor of PDO() which is returned from inside the constructor of PDOPool class.

Unlike mysql, "postgres" does not take charset='something' as part of dsn string therefore it should not be concatenated if database driver is set as "pgsql" instead of "mysql".

For postgres, charset can be set using "options" key of dsn string, as below:

options='--client_encoding=UTF8'

  1. What version of OpenSwoole are you using (show your php --ri openswoole)?
version 4.11.1

  1. What is your machine environment used (show your uname -a & php -v & gcc -v) ?
**uname -a:**
Linux fakhar-HP-Laptop 5.17.5-76051705-generic #202204271406~1651504840~20.04~63e51bd-Ubuntu SMP PREEMPT Wed Ma x86_64 x86_64 x86_64 GNU/Linux

**php -v:**
PHP 8.1.12 (cli) (built: Oct 28 2022 17:39:57) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.12, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.12, Copyright (c), by Zend Technologies

**gcc -v :**
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/11/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 11.3.0-1ubuntu1~22.04' --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-11 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-11-xKiWfi/gcc-11-11.3.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-11-xKiWfi/gcc-11-11.3.0/debian/tmp-gcn/usr --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.3.0 (Ubuntu 11.3.0-1ubuntu1~22.04) 

You can also try the following OpenSwoole support channels:

Feature request: Proroutines (?)

Hi 👋

I was zapping my social feed when a suddenly found this: https://github.com/clue/reactphp-pq
Looks interesting because of the easiness it provides (Laravel surfs a lot on this), I mean...
I know it is "just" multi-processing and Swoole already does a really good job, but!!

What about and API that treats a new process like if its a new "Coroutine"?

A Proroutine (or a better name) is like a Coroutine, but it is actually a new process and all of this could be just a sugar, in the library, around Pool and Manager?
Then whatever is blocking, like unimplemented I/O protocols or CPU-bound tasks, you can delegate to a Proroutine instead of a Coroutine. With the proper disclaimer that a Proroutine is not arbitrary created like a green-thread/coroutine.

Procroutines looks cool as well.

Question about Swoole in cPanel

How is the right way to use swoole

first i installed
pecl install swoole
inphp.iniAdded in the fileextension=swoole.soThis sentence

with "php - m" show swoole

work with php 7.3 or 8 or only 7.2

i need remove php-fpm or only disable or only above?

Swoole curl incorrect send cookie from COOKIEFILE/COOKIEJAR.

Hi.
Recently i discovered the php-swoole library and was surprised how easy it is to write high-performance applications with it in the paradigm familiar to php.

But in the module SWOOLE_HOOK_CURL i found that the library does not work correctly with cookie-files.

  1. php-curl (libcurl) use Netscape-format of cookie-file, but SWOOLE_HOOK_CURL doesn't understand this format.
  2. Even if we dont use cookies from php-curl, but let SWOOLE_HOOK_CURL create a cookie from scratch, SWOOLE_HOOK_CURL will not able to reuse cookies (new request will be executed with broken headers).

Working with a cookie is more complex than just taking the content of the Set-Cookie header and saving it to a file, then sending everything in the Cookie-header.
The server sends each cookie to the client as a separate Set-Cookie header with all service information (for example, lifetime, domain, etc.), and the client must send only the name and contents of the cookie to the server, checking whether the lifetime has expired, whether the domain is correct and stuff like that. I am sure you know better than me how http-cookies work.
Example of how to work correctly with cookie-file can be seen in the library amphp/http-client-cookies.

https://www.php.net/manual/en/function.curl-setopt.php
CURLOPT_COOKIEFILE file to read cookies before request.
CURLOPT_COOKIEJAR file where cookies are written after curl_close().

Hopefully these bugs will be fixed and php-swoole-curl will handle cookie-files correctly.

Thank you for your work.

Cannot execute queries while other unbuffered queries are active.

Error stack

Uncaught PDOException: Cannot execute queries while other unbuffered queries are active.  Consider using PDOStatement::fetchAll().  Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute. in @swoole-src/library/core/Database/PDOStatementProxy.php:64
Stack trace:
#0 /acme/vendor/laravel/framework/src/Illuminate/Database/Connection.php(335): Swoole\Database\PDOStatementProxy->__call('execute', Array)
#1 /acme/vendor/laravel/framework/src/Illuminate/Database/Connection.php(677): Illuminate\Database\Connection->Illuminate\Database\{closure}('select `order_i...', Array)
#3 /acme/vendor/laravel/framework/src/Illuminate/Database/Connection.php(340): Illuminate\Database\Connection->run('select `order_i...', Array, Object(Closure))

What I tried

  1. change to FetchAll , not working

  2. Set atrribute MYSQL_ATTR_USE_BUFFERED_QUERY to true for statement, not working

  3. Close cursor as this cannot-execute-queries-while-other-unbuffered-queries suggests. not working

PHP 8.2: 动态属性被弃用

Deprecated: Creation of dynamic property Swoole\Coroutine\Socket::$__ext_sockets_nonblock is deprecated in @swoole/library/ext/sockets.php on line 217

library/src/ext/sockets.php

Lines 209 to 219 in e99c29b

function swoole_socket_set_block(Socket $socket)
{
if ($socket->isClosed()) {
return false;
}
if (isset($socket->__ext_sockets_nonblock) and $socket->__ext_sockets_nonblock) {
$socket->setOption(SOL_SOCKET, SO_RCVTIMEO, $socket->__ext_sockets_timeout);
}
$socket->__ext_sockets_nonblock = false;
return true;
}

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.