1

I am checking emails with SMTPValidationTool. There are about 2500 rows with emails in the database. PHP script loops through that emails with fetch_assoc() and finds wrong emails. But here is a problem. When I have a small database with 10 emails, everything works perfectly. But when I upload about 2500 or even 1000 emails, after ~ 1 minute 15 seconds or much longer PHP script throws Internal server error 500. All of PHP scripts have set_time_limit(200) and max_execution_time is 300. Nothing helps. I thought that something is saving rows(buffering). I have used MYSQLI_USE_RESULT parameter. But this doesn't help. Help me please! :c I have no idea why this happens... Here is my PHP script:

<?php

set_time_limit(200);

chdir('..');

require 'config/config.php';
require 'vendor/autoload.php';

use SMTPValidateEmail\Validator as SmtpEmailValidator;
$validator = new SmtpEmailValidator();

$db = new mysqli($db['host'], $db['user'], $db['pass'], $db['db']);
if ($db->connect_error) {
    die("Unable to connect database: " . $db->connect_error);
}
$query = $db->query("SELECT email FROM import", MYSQLI_USE_RESULT);
$wrong_count = 0;

while($row = $query->fetch_assoc()){
  $result = $validator->validate($row);
  if (!$result[$row['email']]) {
    $wrong_count+=1;
    $db->query("DELETE FROM import WHERE email='".$row['email']."'");
  }
}
Andrii H.
  • 1,682
  • 3
  • 20
  • 40
  • You can try increase php.ini memory_limit = 64M; But i'm not sure this would help – halojoy Dec 25 '17 at 16:54
  • Turn on debug logging to see what's going on. If you're using [this SMTP validator](https://github.com/zytzagoo/smtp-validate-email), it actually connects to each server present in the email addresses. You may experience a timeout or a memory leak. Check also `$validator->setConnectTimeout(x)` and `$validator->getLog();`. Log yourself what's going on (make sure your logger prints the time) so you have a better idea when this stops. – pyb Dec 25 '17 at 16:58
  • I will try, thanks. – Andrii H. Dec 25 '17 at 17:02
  • Other tips: avoid building your SQL query like this. For security and performance, use https://secure.php.net/manual/en/mysqli.quickstart.prepared-statements.php . If you think that a piece of code is responsible for your issue (like saving the valid email addresses), you can comment this part and rerun your script. In your case I'm pretty sure the validator is the issue. – pyb Dec 25 '17 at 17:03
  • It's a testing area, no security, just fast-testing code :) You mean the validator class is the issue? Should I change a library? – Andrii H. Dec 25 '17 at 17:10

0 Answers0