0
有兩個功能,一個是init
功能,從數據庫中獲得一些信息,然後將帳戶信息轉移到另一個功能從遠程網站上的數據,然後test_function_save_data()
得到正確的數據,並檢查&插入它們進入數據庫。PHP的foreach多個陣列超時
問題是:如果在test_function_save_data()
中使用print_r($post)
,該功能可以正常工作。但刪除此print_r
或將其替換爲sleep()
,可以檢查所有數據並將其插入到數據庫中,但當前頁面未重定向,將顯示空白頁面。
那麼,哪裏出錯?如何解決它?
<?php
function test_function_get_account_init() {
if(test_function_get_sns_account('blog')) {
$b = 0;
foreach (test_function_get_sns_account('blog') as $team_id => $blog_account_name) {
$blog = test_theme_get_blog($team_id, $blog_account_name);
if($blog && is_array($blog['posts'])){
$b += test_function_save_data($blog['posts']);
}
}
echo '<h5successfuly!</h5>';
} else {
echo 'not found.';
}
}
function test_function_save_data($post_data) {
set_time_limit(720);
global $wpdb;
$i = 0;
foreach ($post_data as $post) {
// echo '<div style="display:none;">';
// print_r($post);
// echo '</div>';
if(test_function_check_post_unquine($post['social_origin_id']) && isset($post['social_origin_id'])) {
$social_post_data = array(
'post_title' => $post['post_title'],
'post_content' => $post['post_content'],
'post_status' => 'publish',
'post_author' => get_current_user_id(),
'post_type' => 'social_post'
);
$latest_post_id = wp_insert_post($social_post_data);
if($post['social_origin_url']) {
add_post_meta($latest_post_id, 'social_origin_url', $post['social_origin_url']);
}
if($post['social_origin_id']) {
add_post_meta($latest_post_id, 'social_origin_id', $post['social_origin_id']);
}
if($post['user']) {
add_post_meta($latest_post_id, 'social_origin_user', $post['user']);
}
if($post['user']['team_account']) {
add_post_meta($latest_post_id, $post['user']['site_name'].'_social_user_id', $post['user']['team_account']);
}
if($post['media']) {
add_post_meta($latest_post_id, 'social_origin_thumbnail', $post['media']['url']);
}
$i++;
}
flush();
}
return $i;
}
你可以請格式化您的代碼? –
謝謝。現在格式化。 –