【发布时间】:2018-03-07 12:39:38
【问题描述】:
我尝试了多种方法,仍然无法解决。我有一个包含许多 url 的数组,我使用 foreach 访问该站点并使用 file_get_contents() 提取数据
但404 Not Found nginx/1.12.2 是大约 2 分钟后出现的错误,并且注册了大约 280 条记录。
除了尝试通过插入代码来执行max_execution_time和mysql.connect_timeout还改变ini.php的值0或1200,结果总是一样的,2分钟后显示错误404 Not Found nginx / 1.12.2
在代码中我尝试使用set_time_limit (0); 和sleep (1),但也没有解决问题
ini_set('mysql.connect_timeout','0');
ini_set('max_execution_time', '0');
function create_wordpress_post_with_code() {
if( isset( $_POST['mysubmitbtn'] ) ) {
set_time_limit(0);
$myGetCsv = function ($str) {
return str_getcsv($str, ';');
};
$lines = array_map($myGetCsv, file(''.get_template_directory_uri() . '/list.csv', FILE_IGNORE_NEW_LINES));
foreach($lines as list($var1, $var2)){
set_time_limit(0);
$html = file_get_contents( 'https://example.com/'.$var1.'/'.$var2' );
$document = new DOMDocument();
@$document->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'));
$domxpath = new DOMXPath($document);
// more code here
$post_id = wp_insert_post(
array(
'comment_status' => 'open',
'ping_status' => 'closed',
'post_author' => $author_id,
'post_name' => $slug,
'post_title' => $title,
'post_content' => $content,
'post_status' => 'publish',
'post_type' => 'post'
)
);
sleep(1);
}
}
}
add_action( 'init', 'create_wordpress_post_with_code' );
我可以做些什么来解决这个错误?或者除了执行时间之外,发生此错误的可能原因是什么?
【问题讨论】: