我正在运行一个循环遍历XML文件结果的脚本,并在3个翻译中将帖子插入WP(使用WPML函数)。
脚本正在严重泄漏内存wp_insert_post运行的地方,例如:
-------------- POSTS IS NEW WE ARE GOING TO INSERT !!! --------------
Before post_inserts: 50 mb
after en insert: 54 mb
after es insert: 54 mb
after de insert: 56 mb
-------------- POSTS IS NEW WE ARE GOING TO INSERT !!! --------------
Before post_inserts: 56 mb
after en insert: 56 mb
after es insert: 56 mb
after de insert: 60 mb
-------------- POSTS IS NEW WE ARE GOING TO INSERT !!! --------------
Before post_inserts: 60 mb
after en insert: 62 mb
after es insert: 62 mb
after de insert: 64 mb
-------------- POSTS IS NEW WE ARE GOING TO INSERT !!! --------------
Before post_inserts: 64 mb
after en insert: 66 mb
after es insert: 68 mb
after de insert: 68 mb
......这一直持续到几分钟内我的内存使用量超过200mb。我已经读过这是一个问题,wp_insert_post缓存了查询,所以我尝试了wp_suspend_cache_addition(true)
,这根本没有效果。
以下是相关的代码:
$en_post = array();
$en_post = array(
'post_title' => $property_id.': '.$titleType.' in '.$location,
'post_date' => $listed,
'post_content' => $enDesc,
'post_status' => $postStatus,
'post_author' => $userID,
'post_type' => $postType
);
$es_post = array();
$es_post = array(
'post_title' => $property_id.': '.$titleType.' en '.$location,
'post_date' => $listed,
'post_content' => $esDesc,
'post_status' => $postStatus,
'post_author' => $userID,
'post_type' => $postType
);
$de_post = array();
$de_post = array(
'post_title' => $property_id.': '.$titleType.' im '.$location,
'post_date' => $listed,
'post_content' => $deDesc,
'post_status' => $postStatus,
'post_author' => $userID,
'post_type' => $postType
);
echo "Before post_inserts: ".convert(memory_get_usage(true))."\n\n";
wp_suspend_cache_addition(true);
$en_post_id = wp_insert_post( $en_post );
echo "after en insert: ".convert(memory_get_usage(true))."\n\n";
$es_post_id = wp_insert_post( $es_post );
echo "after es insert: ".convert(memory_get_usage(true))."\n\n";
$de_post_id = wp_insert_post( $de_post );
echo "after de insert: ".convert(memory_get_usage(true))."\n\n";
wp_suspend_cache_addition(false);
$post_ids = array();
$post_ids = array(
'en_post' => $en_post_id,
'es_post' => $es_post_id,
'de_post' => $de_post_id
);
$en_post_id = NULL;
$es_post_id = NULL;
$de_post_id = NULL;
wp_cache_flush();
我已经尝试了wp_cache_flush()
,你可以看到 - 没有骰子。我在每个循环结束时将所有变量设置为NULL并重置数组。
撕开我的头发,如果有人有想法,我真的很感激。