0

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.

  • What web server are you using? – Ivan Shatsky Jul 6 at 8:59
  • According to BrowserSPY it's BitNinja Captcha Server – David Pemberton Jul 6 at 9:22
  • BitNinja isn't a web server, it is rather some intrusion/DDoS prevention software. I will try to formulate the question differently - are you sure that it is apache web server that your hosting provider using, and not an nginx for example? – Ivan Shatsky Jul 6 at 9:34
  • LiteSpeed Web Server – David Pemberton Jul 6 at 9:38
  • $_SERVER['SERVER_SOFTWARE'] Apache – David Pemberton Jul 6 at 9:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.