admin管理员组

文章数量:1332388

I have a custom plugin that inserts multiple rows into a custom table in the wordpress database. After about 50 seconds I get a 504 Gateway Time-out error. The 50 seconds is around about the time it takes to insert ~400 rows. Anything less, and the script completes just fine.

I've added the usual things to wp-config.php and .htaccess

wp-config.php

ini_set('max_execution_time', 1000);
ini_set('max_input_time', 1000);
set_time_limit(1000);

.htaccess

php_value memory_limit 256M
php_value upload_max_filesize 64M
php_value post_max_size 64M
php_value max_execution_time 1000
php_value max_input_time 1000

...but none of these seem to make any difference. The script always timeout after about 50 seconds and I get 504 Gateway Time-out The server didn't respond in time error screen.

My code:

global $wpdb;
$table = 'wp_motorjobs_jobs';
$insert_data = array();

Then I do a foreach loop where I prepare my data based on some other conditions. I end up with this array structure towards the end of the loop:

$job_data = array(
   'title' => $job_title,
   'company' => $job_company,
   'location' => $job_location,
   'type' => $job_type,
   'details' => $job_details,
   'query' => $search_query,
   'site' => $job_site,
   'url' => $url,
   'date' => $job_date
);                  
                
array_push($insert_data, $job_data);

Then I end my loop. This loop could have added hundreds of arrays to $insert_data. All the data are strings.

Then I prepare my sql query:

$query = "INSERT INTO $table ( title, company, location, type, details, query, site, url, date ) VALUES ";
            
foreach ( $insert_data as $row ) {
   $query .= $wpdb->prepare( "(%s, %s, %s, %s, %s, %s, %s, %s, %s),", $row['title'], $row['company'], $row['location'], $row['type'], $row['details'], $row['query'], $row['site'], $row['url'], $row['date'] );
}

$query = rtrim( $query, ',' ) . ';';

$wpdb->query($query);

After this script runs for about 50 seconds I get the 504 Gateway Time-out

Anyone? Cheers.

本文标签: 504 Gateway Timeout after custom plugin inserts data into mysql database