php 循环大部分时间都会中断
我正在使用 file_get_contents 函数来获取 xml api,当我使用 foreach 循环迭代该数组时,它工作正常,但大多数时候我的 php foreach 循环并不是每次都会中断,并且会显示不同类型的消息。有时它给出“function.file-get-contents]:无法打开流:HTTP请求失败”,有时它给出“超过最大时间30秒。
请帮助我。我的代码是
$data = $apiobj->search_slides($query,$per_page,$page);
$count = count($data);
$i=0;
foreach ($data as $key){
$title = $key['TITLE'];
$title2 = substr($title, 0, 35);
echo '<td valign="top">
<div id="slide_thum_des"><strong>Views :</strong> '.$info['VIEWS'].'<br />
<a href="'.$key['DOWNLOADURL'].'">'.$title2.'....</a></div>
</td>';
$i++;
if($i % 6 == 0) {
echo '</tr><tr>';
}
}
$data = $apiobj-> ;search_slides($query,$per_page,$page);
是主要函数,它通过在另一个 php 代码中解析 xml 文件来给出数组。
i am using file_get_contents function to fetch a xml api and when i itrate this array using foreach loop it works fine but most of the time my php foreach loop is breaking not every time and different types of messages are shown. sometimes it gives "function.file-get-contents]: failed to open stream: HTTP request failed" and sometimes it gives "Maximum time 30 second exceeded.
please help me. my code is
$data = $apiobj->search_slides($query,$per_page,$page);
$count = count($data);
$i=0;
foreach ($data as $key){
$title = $key['TITLE'];
$title2 = substr($title, 0, 35);
echo '<td valign="top">
<div id="slide_thum_des"><strong>Views :</strong> '.$info['VIEWS'].'<br />
<a href="'.$key['DOWNLOADURL'].'">'.$title2.'....</a></div>
</td>';
$i++;
if($i % 6 == 0) {
echo '</tr><tr>';
}
}
$data = $apiobj->search_slides($query,$per_page,$page);
is the main function which gives array by parsing xml file in an another php code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你确定它打破了循环吗?
听起来好像最初的 http 请求失败了(由于声音而超时)。
您应该尝试 http 请求并查看它是否有效。
由于您使用的是 file_get_contents 函数,因此您应该首先抑制错误
,然后检查它是否有效
Are you sure it's breaking in the loop?
Sounds like the initial http requests are failing (timing out by the sound of things).
You should try the http request and see it works.
Since you are using the file_get_contents function you should first suppress errors
Then check if it worked