librespeed / speedtest

Self-hosted Speed Test for HTML5 and more. Easy setup, examples, configurable, mobile friendly. Supports PHP, Node, Multiple servers, and more
https://librespeed.org
GNU Lesser General Public License v3.0
12.14k stars 2.19k forks source link

Backend does not work with posgres 12 #438

Open Bezzoom opened 3 years ago

Bezzoom commented 3 years ago

Description

Sharing test result doesn't work

Server

Apache: Server version: Apache/2.4.41 (Ubuntu) Server built: 2021-09-28T11:00:45

PostgreSQL: postgresql-12/focal-updates,focal-security,now 12.8-0ubuntu0.20.04.1 amd64 [installed,automatic] object-relational SQL database, version 12 server

Client

Browser does not metter

Steps to reproduce

Install with manual video, but DB was Postgres table speedtest_users still empty

Expected behaviour

What should have happened

Browser console - empty all requests from browser return 200 code

adolfintel commented 3 years ago

Can you check the web server logs to see if there are errors from the database or results/telemetry.php?

Bezzoom commented 3 years ago

Error.log is empty. Access.log seems normal and dosn't contain nothing suspicious:

172.18.0.92 - - [06/Oct/2021:08:57:24 +0000] "GET /speedtest_worker.js?r=0.5218918802958528 HTTP/1.1" 200 8115 "http://speedtest.testing.kraftway.lan/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0"
172.18.0.92 - - [06/Oct/2021:08:57:24 +0000] "GET /backend/getIP.php?isp=true&distance=km&r=0.9380479893816925 HTTP/1.1" 200 416 "http://speedtest.testing.kraftway.lan/speedtest_worker.js?r=0.5218918802958528" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0"
172.18.0.92 - - [06/Oct/2021:08:57:24 +0000] "GET /backend/empty.php?r=0.9266442136175367 HTTP/1.1" 200 349 "http://speedtest.testing.kraftway.lan/speedtest_worker.js?r=0.5218918802958528" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0"
172.18.0.92 - - [06/Oct/2021:08:57:24 +0000] "GET /backend/empty.php?r=0.03107161833243899 HTTP/1.1" 200 349 "http://speedtest.testing.kraftway.lan/speedtest_worker.js?r=0.5218918802958528" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0"
...
172.18.0.92 - - [06/Oct/2021:08:57:26 +0000] "GET /backend/garbage.php?r=0.6460386987487177&ckSize=100 HTTP/1.1" 200 78869200 "http://speedtest.testing.kraftway.lan/speedtest_worker.js?r=0.5218918802958528" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0"
172.18.0.92 - - [06/Oct/2021:08:57:33 +0000] "POST /backend/empty.php?r=0.8365529267333118 HTTP/1.1" 200 350 "http://speedtest.testing.kraftway.lan/speedtest_worker.js?r=0.5218918802958528" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0"
...
172.18.0.92 - - [06/Oct/2021:08:57:40 +0000] "POST /backend/empty.php?r=0.37652731977902343 HTTP/1.1" 200 349 "http://speedtest.testing.kraftway.lan/speedtest_worker.js?r=0.5218918802958528" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0"
172.18.0.92 - - [06/Oct/2021:08:57:41 +0000] "POST /results/telemetry.php?r=0.7523379223221591 HTTP/1.1" 200 338 "http://speedtest.testing.kraftway.lan/speedtest_worker.js?r=0.5218918802958528" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0"

But I had to make some changes in telemetry_db.php and telemetry_settings.php because my Postgres sserver uses different port:

// Postgresql settings
$PostgreSql_username = 'speedtest';
$PostgreSql_password = 'password';
$PostgreSql_hostname = '172.18.0.63';
$PostgreSql_databasename = 'speedtest';
$PostgreSql_port = '4040';

in getPdo() method:

        if ('postgresql' === $db_type) {
            if (!isset(
                $PostgreSql_hostname,
                $PostgreSql_databasename,
                $PostgreSql_username,
                $PostgreSql_password
            )) {
                return false;
            }

            $dsn = 'pgsql:'
                .'host='.$PostgreSql_hostname
                .';port='.$PostgreSql_port
                .';dbname='.$PostgreSql_databasename;

            return new PDO($dsn, $PostgreSql_username, $PostgreSql_password, $pdoOptions);

Maybe these changes are not enough?

PDO-pgsql is on: изображение

zaimzazali commented 2 years ago

Hey @Bezzoom

Did you manage to solve it? I am facing the same issue.

EDIT --------------------------------------------- I solved the issue with these commands

apt update -y && \ cp -R /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini && \ sed 's/;extension=pdo_pgsql/extension=pdo_pgsql/g' -i /usr/local/etc/php/php.ini && \ sed 's/;extension=pgsql/extension=pgsql/g' -i /usr/local/etc/php/php.ini && \ apt install libpq-dev -y && \ docker-php-ext-install pdo pdo_pgsql pgsql && \ service apache2 restart