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

0

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

normaly it wouldnt use the 100 attempts, only 3 i just made it 100 just in case
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.