2

I've been working on a project where searching for matches between two databases, but when the cronjob runs i'll get an 503 error.

The variable source is the name like 'Peter' or 'Margot'. And name_key is the key of the array like 'name' or 'event'.

global $dbh;
global $dbh_second;

$import_sql = $dbh->prepare('SELECT name_key FROM imports WHERE name = :source');
$import_sql->bindParam(':source', $source, PDO::PARAM_STR);
$import_sql->execute();
$name = $import_sql->fetch(PDO::FETCH_ASSOC);

$source = strtolower($source);
$import_data_sql = $dbh->prepare('SELECT * FROM import_data WHERE source = :source AND import_key = :key');
$import_data_sql->bindParam(':key', $name['name_key'], PDO::PARAM_STR);
$import_data_sql->bindParam(':source', $source, PDO::PARAM_STR);
$import_data_sql->execute();
$import_data = $import_data_sql->fetchAll(PDO::FETCH_ASSOC);


foreach ($import_data as $filter) {

    $column = $filter['import_key'];
    $party_sql = $dbh_second->prepare("SELECT * FROM `digi_gz_parties` WHERE name LIKE :value");
    $party_sql->bindParam(':value', $filter['import_value'], PDO::PARAM_STR);
    $party_sql->execute();

    if($party = $party_sql->fetch(PDO::FETCH_ASSOC)) {

        $import_check_sql = $dbh->prepare('UPDATE import_data SET status = 1 WHERE source = :source AND import_value LIKE :value AND created_at = :max');
        $import_check_sql->bindParam(':max', $filter['max_data'], PDO::PARAM_STR);
        $import_check_sql->bindParam(':value', $filter['import_value'], PDO::PARAM_STR);
        $import_check_sql->bindParam(':source', $source, PDO::PARAM_STR);
        $import_check_sql->execute();

    }

}

Is their another solutions to do this or do i need to set up the timeout seconds higher?

Thanks a lot!

1 Answers1

1

You need to get the records in batches because otherwise it takes too long and gives a timeout. And have a look at some optimization: Indexes, caching and such.

marcokreeft
  • 301
  • 1
  • 7
  • The service is online. The records that the system need to check are 9000 and if i do it with 1000 it 'll do it correctly without an 503 error, but everything above 1000 it 'll give an 503 error. – Pieter Dijkstra Apr 11 '17 at 10:32