swoole / ext-postgresql Goto Github PK
View Code? Open in Web Editor NEW🐘 Coroutine-based client for PostgreSQL
🐘 Coroutine-based client for PostgreSQL
Hi.
PDO have pgsqlGetNotify function with second parameter like sleep.
How to correct use that function?
I wrote some example code (sse server using listen/notify postgres functionality).
See at the line https://github.com/Gemorroj/swoole-sse/blob/main/server.php#L40, is it correct? or i need wrap it to corutine or smething else?
php 8.0.11
MacOS
Swoole 4.6.1
Try to install ext-postgresql v4.6.1
vladimirgordienko@MBP-Vladimir ext-postgresql-4.6.1 % make
/bin/sh /Users/vladimirgordienko/Desktop/ext-postgresql-4.6.1/libtool --mode=compile g++ -I. -I/Users/vladimirgordienko/Desktop/ext-postgresql-4.6.1 -I/Users/vladimirgordienko/Desktop/ext-postgresql-4.6.1/include -I/Users/vladimirgordienko/Desktop/ext-postgresql-4.6.1/main -I/Users/vladimirgordienko/Desktop/ext-postgresql-4.6.1 -I/usr/local/Cellar/php/8.0.11/include/php -I/usr/local/Cellar/php/8.0.11/include/php/main -I/usr/local/Cellar/php/8.0.11/include/php/TSRM -I/usr/local/Cellar/php/8.0.11/include/php/Zend -I/usr/local/Cellar/php/8.0.11/include/php/ext -I/usr/local/Cellar/php/8.0.11/include/php/ext/date/lib -I/Users/vladimirgordienko/Desktop/ext-postgresql-4.6.1 -I/Users/vladimirgordienko/Desktop/ext-postgresql-4.6.1/include -I/usr/local/Cellar/php/8.0.11/include/php/ext/swoole -I/usr/local/Cellar/php/8.0.11/include/php/ext/swoole/include -I/usr/local/opt/postgresql@13/include -I/usr/local/opt/openssl@3/include -DHAVE_CONFIG_H -g -O2 -Wall -Wno-unused-function -Wno-deprecated -Wno-deprecated-declarations -std=c++11 -c /Users/vladimirgordienko/Desktop/ext-postgresql-4.6.1/swoole_postgresql_coro.cc -o swoole_postgresql_coro.lo
mkdir .libs
g++ -I. -I/Users/vladimirgordienko/Desktop/ext-postgresql-4.6.1 -I/Users/vladimirgordienko/Desktop/ext-postgresql-4.6.1/include -I/Users/vladimirgordienko/Desktop/ext-postgresql-4.6.1/main -I/Users/vladimirgordienko/Desktop/ext-postgresql-4.6.1 -I/usr/local/Cellar/php/8.0.11/include/php -I/usr/local/Cellar/php/8.0.11/include/php/main -I/usr/local/Cellar/php/8.0.11/include/php/TSRM -I/usr/local/Cellar/php/8.0.11/include/php/Zend -I/usr/local/Cellar/php/8.0.11/include/php/ext -I/usr/local/Cellar/php/8.0.11/include/php/ext/date/lib -I/Users/vladimirgordienko/Desktop/ext-postgresql-4.6.1 -I/Users/vladimirgordienko/Desktop/ext-postgresql-4.6.1/include -I/usr/local/Cellar/php/8.0.11/include/php/ext/swoole -I/usr/local/Cellar/php/8.0.11/include/php/ext/swoole/include -I/usr/local/opt/postgresql@13/include -I/usr/local/opt/openssl@3/include -DHAVE_CONFIG_H -g -O2 -Wall -Wno-unused-function -Wno-deprecated -Wno-deprecated-declarations -std=c++11 -c /Users/vladimirgordienko/Desktop/ext-postgresql-4.6.1/swoole_postgresql_coro.cc -fno-common -DPIC -o .libs/swoole_postgresql_coro.o
In file included from /Users/vladimirgordienko/Desktop/ext-postgresql-4.6.1/swoole_postgresql_coro.cc:17:
In file included from ./swoole_postgresql_coro.h:20:
In file included from /usr/local/Cellar/php/8.0.11/include/php/ext/swoole/ext-src/php_swoole_cxx.h:19:
/usr/local/Cellar/php/8.0.11/include/php/ext/swoole/ext-src/php_swoole_private.h:25:10: fatal error: 'php_swoole.h' file not found
#include "php_swoole.h"
^~~~~~~~~~~~~~
1 error generated.
make: *** [swoole_postgresql_coro.lo] Error 1
swoole v4.8.8 开启 postgresql 协程,编译 swoole --enable-coroutine-postgresql 出错,
swoole v4.8.8 现在编译 支持postgresql 协程,需要 加什么 ./configure --help 里看不到
/bin/sh /Volumes/Workspaces/ext-postgresql-4.8.0/libtool --mode=link g++ -DPHP_ATOM_INC -I/Volumes/Workspaces/ext-postgresql-4.8.0/include -I/Volumes/Workspaces/ext-postgresql-4.8.0/main -I/Volumes/Workspaces/ext-postgresql-4.8.0 -I/opt/homebrew/Cellar/[email protected]/7.4.29/include/php -I/opt/homebrew/Cellar/[email protected]/7.4.29/include/php/main -I/opt/homebrew/Cellar/[email protected]/7.4.29/include/php/TSRM -I/opt/homebrew/Cellar/[email protected]/7.4.29/include/php/Zend -I/opt/homebrew/Cellar/[email protected]/7.4.29/include/php/ext -I/opt/homebrew/Cellar/[email protected]/7.4.29/include/php/ext/date/lib -I/opt/homebrew/opt/libpq//include -I/Volumes/Workspaces/ext-postgresql-4.8.0 -I/Volumes/Workspaces/ext-postgresql-4.8.0/include -I/opt/homebrew/Cellar/[email protected]/7.4.29/include/php/ext/swoole -I/opt/homebrew/Cellar/[email protected]/7.4.29/include/php/ext/swoole/include -DHAVE_CONFIG_H -Wall -pthread -g -O2 -std=gnu89 -Wl,-rpath,/opt/homebrew/opt/libpq//lib -L/opt/homebrew/opt/libpq//lib -lpthread -o swoole_postgresql.la -export-dynamic -avoid-version -prefer-pic -module -rpath /Volumes/Workspaces/ext-postgresql-4.8.0/modules swoole_postgresql.lo -lpq -lpthread
g++ ${wl}-flat_namespace ${wl}-undefined ${wl}suppress -o .libs/swoole_postgresql.so -bundle .libs/swoole_postgresql.o -L/opt/homebrew/opt/libpq//lib -lpq -lpthread -pthread -Wl,-rpath -Wl,/opt/homebrew/opt/libpq//lib
ld: illegal thread local variable reference to regular symbol _SwooleTG for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [swoole_postgresql.la] Error 1
postgreSQL and MySQL coroutines classes seem to have different methods (past parameters, return values, names...)
Too bad that these 2 classes allowing to query a database asynchronously do not use a common interface, at least for basic operations (connection, query, execute...).
To use these 2 classes and switch from one to the other within the same project (or framework), it is necessary to recode (in php) some wrapper classes, which is neither good for the time spent, nor for the performances.
But maybe I didn't find the right documentation, I only saw this :
https://www.swoole.co.uk/docs/modules/swoole-coroutine-postgres
I cannot make correctly and get error below.
/tmp/ext-postgresql/swoole_postgresql_coro.cc: In function 'void zim_swoole_postgresql_coro_connect(zend_execute_data*, zval*)':
/tmp/ext-postgresql/swoole_postgresql_coro.cc:228:45: error: 'sw_reactor' was not declared in this scope
if (!swReactor_isset_handler(sw_reactor(), PHP_SWOOLE_FD_POSTGRESQL))
^
/tmp/ext-postgresql/swoole_postgresql_coro.cc:235:20: error: 'sw_reactor' was not declared in this scope
if (sw_reactor()->add(sw_reactor(), fd, PHP_SWOOLE_FD_POSTGRESQL | SW_EVENT_WRITE) < 0)
^
/tmp/ext-postgresql/swoole_postgresql_coro.cc:259:50: error: 'sw_reactor' was not declared in this scope
swSocket *_socket = swReactor_get(sw_reactor(), fd);
^
/tmp/ext-postgresql/swoole_postgresql_coro.cc: In function 'int swoole_pgsql_coro_onWrite(swReactor*, swEvent*)':
/tmp/ext-postgresql/swoole_postgresql_coro.cc:400:45: error: 'sw_reactor' was not declared in this scope
return swReactor_onWrite(sw_reactor(), event);
^
/tmp/ext-postgresql/swoole_postgresql_coro.cc: In function 'int swoole_postgresql_coro_close(zval*)':
/tmp/ext-postgresql/swoole_postgresql_coro.cc:1326:20: error: 'sw_reactor' was not declared in this scope
if (sw_reactor())
make: *** [Makefile:194: swoole_postgresql_coro.lo] Error 1
I'm using swoole 4.4.5
After run 'make test'
Warning: PHP Startup: Unable to load dynamic library 'swoole_postgresql.so'
swoole 4.8.2-dev 无法安装这个
在编译这个扩展的时候,出现如下问题:
PHP Warning: PHP Startup: Unable to load dynamic library 'swoole_postgresql.so' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20180731/swoole_postgresql.so (Error relocating /usr/local/lib/php/extensions/no-debug-non-zts-20180731/swoole_postgresql.so: PQgetResult: symbol not found), /usr/local/lib/php/extensions/no-debug-non-zts-20180731/swoole_postgresql.so.so (Error loading shared library /usr/local/lib/php/extensions/no-debug-non-zts-20180731/swoole_postgresql.so.so: No such file or directory)) in Unknown on line 0
请问如何解决呢?
# php --ri swoole_postgresql
swoole_postgresql
Swoole PostgreSQL => enabled
Author => Swoole Team <[email protected]>
Version => 4.5.1
Built => Jun 1 2020 09:54:29
trace_log => enabled
Code:
<?php
Co\run(function () {
$pg = new Swoole\Coroutine\PostgreSQL();
$conn = $pg->connect("host=127.0.0.1 port=5432 dbname=test user=postgres password=1");
var_dump($conn, $pg->error);
});
Output:
bool(true)
NULL
[2020-06-01 13:26:41 @14336.0] WARNING socket_free_defer(:404): close(5) failed, Error: Bad file descriptor[9]
I'm running swoole:4.6.5-php8.0 docker image and compile from source ext-postgresql extension. All fine, but as of version 4.6.6 I can't compile extension. Says php_swoole.h: No such file or directory.
<?php
echo "php version:" . PHP_VERSION . "\n";
echo "swoole version:" . swoole_version(). "\n";
\Co\run(function (){
$obj = new \Co\PostgreSQL();
$obj->connect("host=127.0.0.1 port=5432 dbname=postgres user=postgres password=");
$obj->query("drop table if exists foo");
$obj->query("create table foo(id int, uid int)");
$obj->metaData('foo');
try{
// 不存在的类
new foo;
} catch(\Throwable $e) {
echo "error:" . $e->getMessage() . "\n";
}
echo "无法执行的代码\n";
echo "去掉metaData函数就能正常执行\n";
});
Hello, errors in a prepared statement doesn't get reported, example:
$stmt = $db->prepare("my_query, "SELECT * from non_existing_table");
Here, non_existing_table doesnt exists, but $stmt returns true
and also :
$db->error is null
Hi Team,
I faced with strange behaviour when I send incorrect queries. Here are my cases:
// Direct SQL query:
> INSERT INTO fake_table (id) VALUES (1)
[42P01] ERROR: relation "fake_table" does not exist
// Query via extension:
$db = new Swoole\Coroutine\PostgreSQL();
$db->connect($dsn);
$db->prepare('teststmt', 'INSERT INTO fake_table (id) VALUES ($1)');
echo 'Error code: ' . $db->errCode . PHP_EOL; // Expect non-zero code
echo 'Error message: ' . $db->error . PHP_EOL;
> Error code: 0
> Error message: ERROR: relation "fake_table" does not exist
> LINE 1: INSERT INTO fake_table (id) VALUES ($1)
// Direct SQL query:
> INSERT INTO parts (id, fake_field) VALUES (1, 'Some Data');
[42703] ERROR: column "fake_field" of relation "parts" does not exist
// Query via extension:
$db->prepare('teststmt2', 'INSERT INTO parts (id, fake_field) VALUES ($1, $2)');
> Error code: 0
> ERROR: column "fake_field" of relation "pim_part" does not exist
> LINE 1: INSERT INTO pim_part (id, fake_field) VALUES ($1, $2)
Initially I was expecting an error code like in the PostgreSQL spec. But later I saw that type of errCode
variable is integer. And I don't know how extension can pass error codes with letters (for example 42P01
). Are there any mapping table or something like that? I'm not sure that this feature works correctly.
镜像运行测试代码提示Segmentation fault
代码如下
In file included from /home/ext-postgresql-master/swoole_postgresql_coro.cc:17:0:
/home/ext-postgresql-master/swoole_postgresql_coro.h:28:33: 致命错误:postgresql/libpq-fe.h:没有那个文件或目录
#include <postgresql/libpq-fe.h>
^
,4.5.9没有找到对应版本下了4.4.18,make的时候编译报错:
/usr/local/software/ext-postgresql # make
/bin/sh /usr/local/software/ext-postgresql/libtool --mode=compile g++ -I. -I/usr/local/software/ext-postgresql -DPHP_ATOM_INC -I/usr/local/software/ext-postgresql/include -I/usr/local/software/ext-postgresql/main -I/usr/local/software/ext-postgresql -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -I/usr/local/software/ext-postgresql -I/usr/local/software/ext-postgresql/include -I/usr/local/include/php/ext/swoole -I/usr/local/include/php/ext/swoole/include -DHAVE_CONFIG_H -g -O2 -Wall -Wno-unused-function -Wno-deprecated -Wno-deprecated-declarations -std=c++11 -c /usr/local/software/ext-postgresql/swoole_postgresql_coro.cc -o swoole_postgresql_coro.lo
g++ -I. -I/usr/local/software/ext-postgresql -DPHP_ATOM_INC -I/usr/local/software/ext-postgresql/include -I/usr/local/software/ext-postgresql/main -I/usr/local/software/ext-postgresql -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -I/usr/local/software/ext-postgresql -I/usr/local/software/ext-postgresql/include -I/usr/local/include/php/ext/swoole -I/usr/local/include/php/ext/swoole/include -DHAVE_CONFIG_H -g -O2 -Wall -Wno-unused-function -Wno-deprecated -Wno-deprecated-declarations -std=c++11 -c /usr/local/software/ext-postgresql/swoole_postgresql_coro.cc -fPIC -DPIC -o .libs/swoole_postgresql_coro.o
In file included from /usr/local/software/ext-postgresql/swoole_postgresql_coro.cc:17:
/usr/local/software/ext-postgresql/swoole_postgresql_coro.h:20:10: fatal error: ext/swoole/php_swoole_cxx.h: No such file or directory
20 | #include "ext/swoole/php_swoole_cxx.h"
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:194: swoole_postgresql_coro.lo] Error 1
/usr/local/software/ext-postgresql # ln /usr/local/include/php/ext/swoole/ext-src/php_swoole_cxx.h ext/swoole/php_swoole_cxx.h
ln: ext/swoole/php_swoole_cxx.h: No such file or directory
swoole 4.4.16 pgsql的close 可以帮忙暴露出来吗
Awaiting release swoole-postgresql module for swoole 4.4.17 :) Thank You for development this module. I use connection pools to postgresql, and this module working very well.
Hello.
What about this error:
/tmp/swoole/ext-postgresql/swoole_postgresql_coro.h:28:33: fatal error: postgresql/libpq-fe.h: No such file or directory
#include <postgresql/libpq-fe.h>
^
compilation terminated.
make: *** [swoole_postgresql_coro.lo] Error 1
Thanks.
In file included from /data/opt/ext-postgresql-4.4.18/swoole_postgresql_coro.cc:17:0:
/data/opt/ext-postgresql-4.4.18/swoole_postgresql_coro.h:27:2: error: #error "Ext version does not match the Swoole version"
#error "Ext version does not match the Swoole version"
^
/data/opt/ext-postgresql-4.4.18/swoole_postgresql_coro.cc:59:5: error: ‘php_coro_context’ does not name a type
php_coro_context context;
^
/data/opt/ext-postgresql-4.4.18/swoole_postgresql_coro.cc:73:18: error: ‘php_coro_context’ does not name a type
static sw_inline php_coro_context * php_swoole_postgresql_coro_get_context(zval zobject)
^
/data/opt/ext-postgresql-4.4.18/swoole_postgresql_coro.cc: In function ‘void zim_swoole_postgresql_coro_connect(zend_execute_data, zval*)’:
/data/opt/ext-postgresql-4.4.18/swoole_postgresql_coro.cc:280:5: error: ‘string’ is not a member of ‘zend’
zend::string dsn(conninfo);
example:
$pg = $this->pgsqlClientDbPool->get(1);
$s = $pg->query("select * from tbl_company where company_id=12312312"); //something not exist
$data = $pg->fetchAll($s); // the $data variable will be false
foreach ($data as $datum) // there is a warning show up
// do something
The $data variable will be FALSE, and a warning shown up in foreach statement. The code will go only if I check whether the $data is false and then give it an empty array value.
It's different behavior than most client implement.
To change this behavior is easy, change line 864 in swoole_postgresql_coro.cc file, from FAILURE to SUCCESS.
The fetchAll above will return an empty array.
The problem happens with master branch.
I have wrote a simple code to demonstrate the problem.
function getRandomData(): Generator
{
for ($i = 0; $i < 10000; $i++) {
yield [
md5((string)random_int(100000, 900000)),
md5((string)random_int(100000, 900000))
];
}
}
function seedDataSwoole(\Swoole\Coroutine\PostgreSQL $connection): void
{
$connection->query("DROP TABLE IF EXISTS test");
$connection->query("CREATE TABLE test (domain VARCHAR(63), tld VARCHAR(63), PRIMARY KEY (domain, tld))");
$connection->prepare("insert", "INSERT INTO test VALUES (\$1, \$2)");
foreach (getRandomData() as $row) {
$connection->execute("insert", $row);
}
$connection->query("DEALLOCATE insert");
}
Swoole\Coroutine\run(function () {
$connection = new \Swoole\Coroutine\PostgreSQL();
$connection->connect("host=127.0.0.1 port=5434 user='makise' password='el-psy-congroo' dbname='makise'");
// uncomment this only for the first run
// seedDataSwoole($connection);
$start = microtime(true);
for ($i = 0; $i < 100; $i++) {
$result = $connection->query('SELECT * FROM test');
while ($row = $connection->fetchAssoc($result)) {
}
}
$end = microtime(true);
$total = $end - $start;
printf("Execution time for Swoole client: %f secs\n", $total);
printf("Peak memory usage for Swoole client: %.2f kb\n", memory_get_peak_usage() / 1024);
});
Segmentation fault occurs really random. And it happens only when calling single row fetch functions.
When I call fetchAll - segmentation fault doesn't happens.
php benchmark/select-swoole-raw.php
Execution time for Swoole client: 0.416035 secs
Peak memory usage for Swoole client: 2079.92 kb
php benchmark/select-swoole-raw.php
Execution time for Swoole client: 0.423457 secs
Peak memory usage for Swoole client: 2079.92 kb
php benchmark/select-swoole-raw.php
Segmentation fault
php benchmark/select-swoole-raw.php
Execution time for Swoole client: 0.405166 secs
Peak memory usage for Swoole client: 2079.92 kb
php benchmark/select-swoole-raw.php
Execution time for Swoole client: 0.419964 secs
Peak memory usage for Swoole client: 2079.92 kb
php benchmark/select-swoole-raw.php
Segmentation fault
php benchmark/select-swoole-raw.php
Segmentation fault
php benchmark/select-swoole-raw.php
Segmentation fault
php benchmark/select-swoole-raw.php
Execution time for Swoole client: 0.438378 secs
Peak memory usage for Swoole client: 2079.92 kb
Here is what does strace say:
....
poll([{fd=4, events=POLLIN|POLLERR}], 1, -1) = 1 ([{fd=4, revents=POLLIN}])
recvfrom(4, "\27\3\3 \21", 5, 0, NULL, NULL) = 5
recvfrom(4, "\t\217\211jhHM4\360s\232\316\377\3366\353\276\222\373\216Q.\265c\341eQe(Rd\255"..., 8209, 0, NULL, NULL) = 8209
poll([{fd=4, events=POLLIN|POLLERR}], 1, -1) = 1 ([{fd=4, revents=POLLIN}])
recvfrom(4, "\27\3\3 \21", 5, 0, NULL, NULL) = 5
recvfrom(4, "[\262\7Y\312\370;\225\256\0J\354\222Y\247qD\"`Z\261H\352\304X\353~\210\242q\30`"..., 8209, 0, NULL, NULL) = 8209
poll([{fd=4, events=POLLIN|POLLERR}], 1, -1) = 1 ([{fd=4, revents=POLLIN}])
recvfrom(4, "\27\3\3 \21", 5, 0, NULL, NULL) = 5
recvfrom(4, "\244T9B\321\36L\231\363\304\265w\5\355\214\206\16\365\277\274p^\223W\227\345\367\2565\316\355W"..., 8209, 0, NULL, NULL) = 8209
poll([{fd=4, events=POLLIN|POLLERR}], 1, -1) = 1 ([{fd=4, revents=POLLIN}])
recvfrom(4, "\27\3\3 \21", 5, 0, NULL, NULL) = 5
recvfrom(4, "\206L\365\345\362\25D\320\301/\247\35\244\255\317[\343Y\300\210\255hul\37\30\350\337\360\210\304&"..., 8209, 0, NULL, NULL) = 8209
poll([{fd=4, events=POLLIN|POLLERR}], 1, -1) = 1 ([{fd=4, revents=POLLIN}])
recvfrom(4, "\27\3\3 \21", 5, 0, NULL, NULL) = 5
recvfrom(4, "7\306+u\345\1\233\261\367\342]\0\262\261e\10\374P5\260\273\0\337\312\2'\vuy\n\204`"..., 8209, 0, NULL, NULL) = 8209
poll([{fd=4, events=POLLIN|POLLERR}], 1, -1) = 1 ([{fd=4, revents=POLLIN}])
recvfrom(4, "\27\3\3\16O", 5, 0, NULL, NULL) = 5
recvfrom(4, "\330\335\17$R\323\252\334\322\315\n\272\377$\273\16\2534U\277\276Zd:\303\363\326\376*yB\322"..., 3663, 0, NULL, NULL) = 3663
epoll_ctl(3, EPOLL_CTL_DEL, 4, NULL) = 0
--- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0x55c00a9207c8} ---
+++ killed by SIGSEGV +++
Here is what does gdb say:
gdb --args php benchmark/select-swoole-raw.php
(gdb) run
Starting program: /usr/bin/php benchmark/select-swoole-raw.php
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff2db5339 in PQgetisnull () from /lib/x86_64-linux-gnu/libpq.so.5
@matyhtf can you help with debug?
$pg = new \Swoole\Coroutine\PostgreSQL();
$dsn = 'host=localhost;dbname=test;user=user;password=pswd';
$pg->connect($dsn);
$res = $pg->query('select name from users where id=1');
$pg->fetchRow($res); // it's ok
$res = $pg->query('select name, pg_sleep(4) from users where id=1');
echo $pg->error; // ontimeout
$res = $pg->query('select name from users where id=1');
if ($res) {
$pg->fetchRow($res);
} else {
// goto here
echo $pg->error; // ontimeout
}
if (!$pg->connect($dsn)) {
echo $pg->error; // ontimeout
}
$pg = new \Swoole\Coroutine\PostgreSQL();
$pg->connect($dsn);
$res = $pg->query('select name from users where id=1');
$pg->fetchRow($res); // it's ok
at swoole_postgresql_coro.cc#353
object->timeout = SW_PGSQL_CONNECT_TIMEOUT;
SW_PGSQL_CONNECT_TIMEOUT
defined to 3.0
no method set the timeout
value now.
The code has been commented out
/*if ((PGG(auto_reset_persistent) & 2) && PQstatus(pgsql) != CONNECTION_OK) {
PQreset(pgsql);
}*/
Why
ext-postgresql/swoole_postgresql_coro.h:20:10: fatal error: ext/swoole/ext-src/php_swoole_cxx.h: No such file or directory
20 | #include "ext/swoole/ext-src/php_swoole_cxx.h"
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I already have libpq
, via apt install libpq-dev
, and installed swoole via pecl, but compilation is bug (I already try master and release v4.6.1)
ext-postgresql-master/swoole_postgresql_coro.h:54:5: error: 'swTimer_node' does not name a type; did you mean 'swHeap_node'?
swoole和ext-postgresql都是master
Code:
<?php
Co\run(function () {
$pg = new Swoole\Coroutine\PostgreSQL();
$conn = $pg->connect("host=127.0.0.1 port=5432 dbname=test user=postgres password=1");
var_dump($conn, $pg->error);
$res = $pg->query('select * from tb_user');
\Swoole\Coroutine::sleep(1); // yield
var_dump($pg->fetchArray($res), $pg->error);
});
Output:
bool(true)
NULL
bool(false)
NULL
报错信息:
/root/download/ext-postgresql-4.4.16/swoole_postgresql_coro.h:35:33: fatal error: postgresql/libpq-fe.h: No such file or directory
#include <postgresql/libpq-fe.h>
^
compilation terminated.
make: *** [swoole_postgresql_coro.lo] Error 1
已安装:yum install postgresql-devel
The following code produce a segmentation fault. The problem is that the registration of coroutine callbacks were done only in the connect method. I have a fork that fix this bug. I can do a pull request if needed.
<?php
$db;
\Co\run(function() use (&$db){
$db = new \Swoole\Coroutine\PostgreSQL();
$db->connect("host=127.0.0.1 port=5432 dbname=wireskel user=wireskel password=xxxxxx");
});
\Co\run(function () use ($db) {
$res = $db->query('SELECT * from _cred_user'); // Segmentation Fault
});
I encountered this error when trying to install the postgresql extension.
In file included from /tmp/sw/ext-postgresql/swoole_postgresql_coro.cc:17:
./swoole_postgresql_coro.h:20:10: fatal error: 'php_swoole_cxx.h' file not found
#include "php_swoole_cxx.h"
^~~~~~~~~~~~~~~~~~
1 error generated.
make: *** [swoole_postgresql_coro.lo] Error 1
code:
$pool = new PDOPool((new PDOConfig) ->withDriver(PDOConfig::DRIVER_PGSQL) ->withHost('127.0.0.1') ->withPort(5432) ->withDbName('postgres') ->withUsername('postgres') ->withPassword('password') ->withCharset('utf8') );
exception:
thrown in @swoole-src/library/core/Database/PDOPool.php on line 44 PHP Fatal Error 'yii\base\ErrorException' with message '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=127....', 'postgres', 'password', 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()
ubuntu 20.04 linux
git swoole-src install success.
git clone ext-postgresql.
phpize
./configure
make times wrong:
/bin/bash /home/c04/ext-postgresql/libtool --mode=compile g++ -I. -I/home/c04/ext-postgresql -DPHP_ATOM_INC -I/home/c04/ext-postgresql/include -I/home/c04/ext-postgresql/main -I/home/c04/ext-postgresql -I/usr/include/php/20190902 -I/usr/include/php/20190902/main -I/usr/include/php/20190902/TSRM -I/usr/include/php/20190902/Zend -I/usr/include/php/20190902/ext -I/usr/include/php/20190902/ext/date/lib -I/home/c04/ext-postgresql -I/home/c04/ext-postgresql/include -I/usr/include/php/20190902/ext/swoole -I/usr/include/php/20190902/ext/swoole/include -DHAVE_CONFIG_H -g -O2 -Wall -Wno-unused-function -Wno-deprecated -Wno-deprecated-declarations -std=c++11 -c /home/c04/ext-postgresql/swoole_postgresql_coro.cc -o swoole_postgresql_coro.lo
mkdir .libs
g++ -I. -I/home/c04/ext-postgresql -DPHP_ATOM_INC -I/home/c04/ext-postgresql/include -I/home/c04/ext-postgresql/main -I/home/c04/ext-postgresql -I/usr/include/php/20190902 -I/usr/include/php/20190902/main -I/usr/include/php/20190902/TSRM -I/usr/include/php/20190902/Zend -I/usr/include/php/20190902/ext -I/usr/include/php/20190902/ext/date/lib -I/home/c04/ext-postgresql -I/home/c04/ext-postgresql/include -I/usr/include/php/20190902/ext/swoole -I/usr/include/php/20190902/ext/swoole/include -DHAVE_CONFIG_H -g -O2 -Wall -Wno-unused-function -Wno-deprecated -Wno-deprecated-declarations -std=c++11 -c /home/c04/ext-postgresql/swoole_postgresql_coro.cc -fPIC -DPIC -o .libs/swoole_postgresql_coro.o
/home/c04/ext-postgresql/swoole_postgresql_coro.cc: In function ‘void zim_swoole_postgresql_coro_connect(zend_execute_data*, zval*)’:
/home/c04/ext-postgresql/swoole_postgresql_coro.cc:351:44: error: use of enum ‘swFd_type’ without previous declaration
351 | object->socket = make_socket(fd, (enum swFd_type) PHP_SWOOLE_FD_POSTGRESQL);
| ^~~~~~~~~
/home/c04/ext-postgresql/swoole_postgresql_coro.cc:367:9: error: ‘swWarn’ was not declared in this scope
367 | swWarn("Unable to connect to PostgreSQL server: [%s]", PQhost(pgsql));
| ^~~~~~
/home/c04/ext-postgresql/swoole_postgresql_coro.cc: In function ‘void swoole_pgsql_coro_onTimeout(swoole::Timer*, swoole::TimerNode*)’:
/home/c04/ext-postgresql/swoole_postgresql_coro.cc:417:9: error: ‘swWarn’ was not declared in this scope
417 | swWarn(" [%s, %s] ", feedback, err_msg);
| ^~~~~~
/home/c04/ext-postgresql/swoole_postgresql_coro.cc: In function ‘void connect_callback(pg_object*, swoole::Reactor*, swoole::Event*)’:
/home/c04/ext-postgresql/swoole_postgresql_coro.cc:455:13: error: ‘swWarn’ was not declared in this scope
455 | swWarn("PQconnectPoll unexpected status");
| ^~~~~~
/home/c04/ext-postgresql/swoole_postgresql_coro.cc: In function ‘void zim_swoole_postgresql_coro_metaData(zend_execute_data*, zval*)’:
/home/c04/ext-postgresql/swoole_postgresql_coro.cc:1251:9: error: ‘swWarn’ was not declared in this scope
1251 | swWarn("error:[%s]", err_msg);
| ^~~~~~
make: *** [Makefile:192: swoole_postgresql_coro.lo] Error 1
php版本:
php -v
PHP 7.4.30 (cli) (built: Jun 9 2022 09:30:03) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
swoole版本
php --ri swoole
swoole
Swoole => enabled
Author => Swoole Team <[email protected]>
Version => 4.5.11
Built => Sep 7 2022 17:48:32
coroutine => enabled
kqueue => enabled
rwlock => enabled
pcre => enabled
zlib => 1.2.11
brotli => E16777225/D16777225
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 => 262144 => 262144
libpq:
brew info libpq
==> libpq: stable 14.5 (bottled) [keg-only]
Postgres C API library
https://www.postgresql.org/docs/14/libpq.html
/usr/local/Cellar/libpq/14.5 (2,340 files, 27.9MB)
Poured from bottle on 2022-09-08 at 14:48:08
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/libpq.rb
License: PostgreSQL
==> Dependencies
Required: krb5 ✔, [email protected] ✔
==> Caveats
libpq is keg-only, which means it was not symlinked into /usr/local,
because conflicts with postgres formula.
If you need to have libpq first in your PATH, run:
echo 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.zshrc
For compilers to find libpq you may need to set:
export LDFLAGS="-L/usr/local/opt/libpq/lib"
export CPPFLAGS="-I/usr/local/opt/libpq/include"
For pkg-config to find libpq you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/libpq/lib/pkgconfig"
==> Analytics
install: 192,636 (30 days), 492,223 (90 days), 1,669,899 (365 days)
install-on-request: 75,358 (30 days), 190,975 (90 days), 631,460 (365 days)
build-error: 3 (30 days)
gcc版本:
gcc --version
Apple clang version 14.0.0 (clang-1400.0.29.102)
Target: x86_64-apple-darwin21.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
系统:
sw_vers
ProductName: macOS
ProductVersion: 12.4
BuildVersion: 21F79
Darwin luowencaideMacBook-Pro.local 21.5.0 Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:22 PDT 2022; root:xnu-8020.121.3~4/RELEASE_X86_64 x86_64
make编译失败:
[email protected]/7.4.30/include/php/ext/swoole/include -I/usr/local/opt/libpq/include -DHAVE_CONFIG_H -g -O2 -Wall -Wno-unused-function -Wno-deprecated -Wno-deprecated-declarations -std=c++11 -c /Volumes/Documents/下载/ext-postgresql-4.8.0/swoole_postgresql.cc -fno-common -DPIC -o .libs/swoole_postgresql.o
In file included from /Volumes/Documents/下载/ext-postgresql-4.8.0/swoole_postgresql.cc:18:
./php_swoole_postgresql.h:21:10: fatal error: 'ext/swoole/ext-src/php_swoole_cxx.h' file not found
#include "ext/swoole/ext-src/php_swoole_cxx.h"
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
make: *** [swoole_postgresql.lo] Error 1
Please answer these questions before submitting your issue. Thanks!
What did you do? If possible, provide a simple script for reproducing the error.
Binding variable is not working on some queries on 4.4.3 postgresql extension. The 4.4.3+ with latest version of postgresql extension also cannot work properly for binding variables.
$pg -> prepare("my_query", "INSERT INTO b SELECT * FROM a WHERE a.testid = $1 AND a.logid IN (SELECT logid FROM a EXCEPT SELECT logid FROM b);");
$res = $pg->execute("my_query", array(2));
What did you expect to see?
Running result correctly
What did you see instead?
Binding cannot work
What version of Swoole are you using (show your php --ri swoole
)?
Swoole => enabled
Author => Swoole Team [email protected]
Version => 4.4.3
Built => Sep 10 2019 12:30:01
coroutine => enabled
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
sockets => enabled
openssl => OpenSSL 1.1.1 11 Sep 2018
http2 => enabled
pcre => enabled
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
mysqlnd => 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 7.2.19-0ubuntu0.18.04.2 (cli) (built: Aug 12 2019 19:34:28) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.19-0ubuntu0.18.04.2, Copyright (c) 1999-2018, by Zend Technologies
Hello, guys!
I see there was some progress for supporting Swoole 4.5.0 on the master branch, but it was months ago.
Do you have any plans for this? Or maybe you can share a manual or an example of how to upgrade Swoole extensions to 4.5.0
安装扩展时报错:
In file included from /home/ext-postgresql-master/swoole_postgresql_coro.cc:17:0:
/home/ext-postgresql-master/swoole_postgresql_coro.h:35:33: fatal error: postgresql/libpq-fe.h: No such file or directory
#include <postgresql/libpq-fe.h>
新版swoole下这个编译不通过,报了一堆错误
v4.4.16,当sql比较长时,比如insert into value(500行记录) 会一直卡住。
不知道怎么解决,看源码看不懂
Right now, version 4.4.14 is throwing when creating a new client connection :
WARNING swProtocol_recv_check_length (ERRNO 1201): package is too big, remote_addr=unknown:0, length=395
But I am not able to compile a newer version of Swoole (4.4.15) because ext-postgresql is not released for version 4.4.15 (compiling throws ./swoole_postgresql_coro.h:27:2: error: "Ext version does not match the Swoole version"
).
Thanks!
PROBLEM:
In file included from /DIR/ext-postgresql-master/swoole_postgresql_coro.cc:17:0:
/DIR/ext-postgresql-master/swoole_postgresql_coro.h:28:10: fatal error: postgresql/libpq-fe.h: Нет такого файла или каталога
#include <postgresql/libpq-fe.h>
^~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Makefile:194: recipe for target 'swoole_postgresql_coro.lo' failed
make: *** [swoole_postgresql_coro.lo] Error 1
RESOLVE:
So try installing libpq-dev or its equivalent for your OS:
For Ubuntu/Debian systems: ```sudo apt-get install libpq-dev```
On Red Hat Linux (RHEL) systems: ```yum install postgresql-devel```
For Mac Homebrew: ```brew install postgresql```
For Mac MacPorts PostgreSQL: ```gem install pg -- --with-pg-config=/opt/local/lib/postgresql[version number]/bin/pg_config```
For OpenSuse: ```zypper in postgresql-devel```
For ArchLinux: ```pacman -S postgresql-libs```
make
/bin/bash /tmp/ext-postgresql/libtool --mode=compile g++ -I. -I/tmp/ext-postgresql -I/tmp/ext-postgresql/include -I/tmp/ext-postgresql/main -I/tmp/ext-postgresql -I/usr/include/php/20210902 -I/usr/include/php/20210902/main -I/usr/include/php/20210902/TSRM -I/usr/include/php/20210902/Zend -I/usr/include/php/20210902/ext -I/usr/include/php/20210902/ext/date/lib -I/tmp/ext-postgresql -I/tmp/ext-postgresql/include -I/usr/include/php/20210902/ext/swoole -I/usr/include/php/20210902/ext/swoole/include -DHAVE_CONFIG_H -g -O2 -Wall -Wno-unused-function -Wno-deprecated -Wno-deprecated-declarations -std=c++11 -I/usr/include/postgresql -DENABLE_PHP_SWOOLE_POSTGRESQL -DZEND_COMPILE_DL_EXT=1 -c /tmp/ext-postgresql/swoole_postgresql.cc -o swoole_postgresql.lo -MMD -MF swoole_postgresql.dep -MT swoole_postgresql.lo
libtool: compile: g++ -I. -I/tmp/ext-postgresql -I/tmp/ext-postgresql/include -I/tmp/ext-postgresql/main -I/tmp/ext-postgresql -I/usr/include/php/20210902 -I/usr/include/php/20210902/main -I/usr/include/php/20210902/TSRM -I/usr/include/php/20210902/Zend -I/usr/include/php/20210902/ext -I/usr/include/php/20210902/ext/date/lib -I/tmp/ext-postgresql -I/tmp/ext-postgresql/include -I/usr/include/php/20210902/ext/swoole -I/usr/include/php/20210902/ext/swoole/include -DHAVE_CONFIG_H -g -O2 -Wall -Wno-unused-function -Wno-deprecated -Wno-deprecated-declarations -std=c++11 -I/usr/include/postgresql -DENABLE_PHP_SWOOLE_POSTGRESQL -DZEND_COMPILE_DL_EXT=1 -c /tmp/ext-postgresql/swoole_postgresql.cc -MMD -MF swoole_postgresql.dep -MT swoole_postgresql.lo -fPIC -DPIC -o .libs/swoole_postgresql.o
/tmp/ext-postgresql/swoole_postgresql.cc:282:55: error: macro "SW_INIT_CLASS_ENTRY" passed 5 arguments, but takes just 4
282 | swoole_postgresql_coro_methods);
| ^
In file included from /usr/include/php/20210902/ext/swoole/ext-src/php_swoole_cxx.h:19,
from /tmp/ext-postgresql/php_swoole_postgresql.h:21,
from /tmp/ext-postgresql/swoole_postgresql.cc:18:
/usr/include/php/20210902/ext/swoole/ext-src/php_swoole_private.h:504: note: macro "SW_INIT_CLASS_ENTRY" defined here
504 | #define SW_INIT_CLASS_ENTRY(module, namespace_name, short_name, methods)
|
/tmp/ext-postgresql/swoole_postgresql.cc: In function ‘void swoole_postgresql_init(int)’:
/tmp/ext-postgresql/swoole_postgresql.cc:278:5: error: ‘SW_INIT_CLASS_ENTRY’ was not declared in this scope
278 | SW_INIT_CLASS_ENTRY(swoole_postgresql_coro,
| ^~~~~~~~~~~~~~~~~~~
make: *** [Makefile:205: swoole_postgresql.lo] Ошибка 1
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.