0

Php-fpm error log file is still logging my error even using try-catch

$NUM_OF_ATTEMPTS = 100;
$attempts = 0;
        do
            {
            try
                {
                $db = new SQLite3('proxies/socks5.db');
                $results = $db->query('SELECT proxy FROM socks5proxies WHERE timeout <= ' . $settimeout . $countryq . ';');
                while ($row = $results->fetchArray())
                    {
                    echo $row['proxy'] . "\r\n";
                    }
                }

            catch(Exception $e)
                {
                $attempts++;
                sleep(1);
                continue;
                }

            break;
            }

        while ($attempts < $NUM_OF_ATTEMPTS);

Expected result:

Retry on error, and don't log the error

Actual results:

Logs the error in the php-fpm error log file: thrown in /var/www/html/api.php on line 200 [10-Jan-2019 14:00:49 UTC] PHP Warning: SQLite3::query(): Unable to prepare statement: 11, database disk image is malformed in /var/www/html/api.php on line 140 [10-Jan-2019 14:00:49 UTC] PHP Fatal error: Uncaught Error: Call to a member function fetchArray() on boolean in /var/www/html/api.php:141 Stack trace: #0 {main} thrown in /var/www/html/api.php on line 141

Thiplol
  • 165
  • 1
  • 1
  • 13

1 Answers1

1

Call SQLite3::enableExceptions to tell PHP it should throw exceptions instead of standard errors:

try {
    $db = new SQLite3('proxies/socks5.db');
    $db->enableExceptions(true);
    $results = $db->query('...');
} catch (\Exception $e) {
}

In any case, if you need to do 100 attempts to get this to work, then this really isn't the angle you should be taking to fix it.

Alex Howansky
  • 50,515
  • 8
  • 78
  • 98
  • normaly it wouldnt use the 100 attempts, only 3 i just made it 100 just in case – Thiplol Jan 10 '19 at 18:30
  • Let me rephrase: If you need to do more than 1 attempt to get this to work, then this really isn't the angle you should be taking to fix it. Fix the problem, not the symptom. – Alex Howansky Jan 10 '19 at 18:33