I have developed a wordpress plugin that reads large custom xml files and imports the information as custom post types and a lot of post meta information. So I am calling a lot of database transactions. The plugin runs for several minutes within one POST’ed process and then aborts with out of memory (250 MB).

Tracking the problem down to a minimum I have a minimal example that shows the problem. This example is leaking about 18 kbyte and this is summing heavily up during runtime of the plugin. The query checks if a post with a given title exists ($title)

echo "<p>memory: " . memory_get_usage() . "</p>";
global $wpdb;
$poststable = $wpdb->prefix."posts";
$items = $wpdb->get_results("SELECT ID FROM $poststable WHERE post_title="$title"");
unset($items);
$wpdb->flush();
echo "<p>memory: " . memory_get_usage() . "</p>";

The output is
memory: 80777008
memory: 80795376
so the difference is about 18 kbyte. Where are those bytes? Although this is a small amount of memory it is summing up to several hundred megabytes.

Thanks!
Chris

1 Answer
1

@IlmarsL: thanks! I really did not think of that. I had the plugin Query Monitor enabled and this was the problem… Turning Query Monitor off solved the problem and memory did no more longer increase.

Leave a Reply

Your email address will not be published. Required fields are marked *