如何解决如何运行x次php脚本?
我有一个网站以以下格式返回json:domain.tld / json / 1 /,domain.tld / json / 2 /,domain.tld / json / 3 /,domain.tld / json / 4 / ,domain.tld / json / 5 /等。
我知道每天json的数量,可以说今天有5个。我想将5放入我的字段中,然后按get all。该脚本应遍历所有页面并将其插入我的第二个网站,但现在只插入一页,我不明白为什么。对不起,我的英语不好,我不是本地人。这是我的代码:
aws efs create-file-system
解决方法
function request($i) {
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,'https://mypage.tld/json/'.$i.'/');
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,5);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
curl_setopt($ch,CURLOPT_REFERER,"https://mypage.tld/");
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
if(isset($_POST["get_all"])) {
for ($i = 0; $i < $_POST["get_all"]; $i++) {
$json_data = trim(request($i));
$json_data = json_decode($data,true);
$insert_post = wp_insert_post([
'post_title' => $post['post_title'],'post_content' => $post['post_content'],'post_status' => 'publish','post_type' => 'news',]);
}
}
如果您将页面的完整回复发送给我,我将为您提供更多帮助。 错误的代码: https://mypage.tld/$page_number/应该是https://mypage.tld/json/'.$page_number.'/
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。