I've tried in several ways and still can not solve. I have an array with many urls, I use foreach to access the site and extract data with file_get_contents()
But 404 Not Found nginx/1.12.2
is the error that appears after approximately 2 minutes and registering approximately 280 records.
In addition to trying to execute max_execution_time
and mysql.connect_timeout
by inserting in the code also changing in the ini.php
the value of 0
or 1200
, the result is always the same, after 2 minutes it displays the error 404 Not Found nginx / 1.12.2
in the code I tried to use set_time_limit (0);
and sleep (1)
but it is not solving the problem either
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' );
What can I do to resolve this error? Or what are the probable reasons that this error is happening besides possibly because of the execution time?