For循环不能超过43次

I am running this PHP script to get profile pictures of 396 Facebook users. The loop does not work after 43 results. What could have gone wrong? Please guide. Thanks.

<html>
<head>
</head>
<body>
 <?php
error_reporting (0 );
 for ($i = 4; $i <= 400; $i++)
 {

            $to_send = "http://graph.facebook.com/";
            $to_send_new = $to_send.$i;
            $content = file_get_contents($to_send_new);
            $parsed = json_decode($content);
            $link = $parsed->link;
            $link = str_replace("http://www.facebook.com","https://graph.facebook.com",$link);
            $link .="/picture?width=6000&height=6000";
?>
 <img src=' <?php echo $link ?>' >
 <br>
 <?php
 }
 ?>
</body>
</html>

Seems like your script time is running out. Add this

<?php
error_reporting (0 );
set_time_limit(0);// Setting an infinite timeout limit.

set_time_limit(0); may solve your problem

Another technique you can use. Request will go one after finishing another

page1.php

<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" 
                                          type="text/javascript"></script>

<script>
$(document).ready(function(e) {
    var i=4;
    var getResponse = function() {
        $.ajax({
            type:"GET",
            url:"page2.php",
            data:{i:i},
            async:false,
            success: function(response) {
                i++;
                $("body").append(response);
                getResponse();
            }
        });
    }
    //setTimeout(getResponse,1000);
    getResponse();
});
</script>
</head>
<body>

</body>
</html>

page2.php

<?php
error_reporting(0);
$i = $_GET['i'];

$to_send = "http://graph.facebook.com/";
$to_send_new = $to_send.$i;
$content = file_get_contents($to_send_new);
$parsed = json_decode($content);
$link = $parsed->link;
$link= str_replace("http://www.facebook.com","https://graph.facebook.com",$link);
$link .="/picture?width=6000&height=6000";
?>
<img src=' <?php echo $link ?>' >
<br>

http://graph.facebook.com/43 gives error Unsupported get request. Might want to have a look at that.

Some ID's dont have data with them. Thats a separate issue.

So what you are trying to do here is just display the user profile picture for Facebook accounts, by just increasing the id in your loop without regard to whether or not a Facebook account with that id actually exists …?

You don’t need to query the API for the link to their profile for that – you can just use the numeric id instead – https://graph.facebook.com/4/picture gives you Mark’s profile pic, no need to get his username first.