clankill3r Posted June 14, 2011 Share Posted June 14, 2011 I have a php that get's tweets from 102 people to store them in a database. Only i get a error about a time limit exceded (60sec). I tried to solve it by this: if($id <= 150){ $id ++; $headerLoc = "updateTweets.php"; header("Location: ".$headerLoc."?id=".$id.""); } else { echo "done ok"; } but then i get a error from chrome that the site has a redirect loop (it comes to 22). What would be a good way to solve? Quote Link to comment https://forums.phpfreaks.com/topic/239371-too-many-redirects/ Share on other sites More sharing options...
redixx Posted June 14, 2011 Share Posted June 14, 2011 I'm not really sure I understand your problem. What is the error about a time limit coming from? Twitter? But the reason for the infinite redirect is because you are basically saying "if $id is less than 150, keep redirecting until it equals 150". So if $id is equal to 1, it's going to redirect 149 times before it gets to 150. Not really sure what you are trying to accomplish with that, to be honest. Quote Link to comment https://forums.phpfreaks.com/topic/239371-too-many-redirects/#findComment-1229745 Share on other sites More sharing options...
clankill3r Posted June 14, 2011 Author Share Posted June 14, 2011 I can't remember the exact error, problem is i can't look at it cause then i hit a 150 request per hour limit by twitter and that makes me have to wait an hour before i can continue working. It's something that it takes to long before the site is ready loading. For the redirect thing, it was to avoid that page loading takes to long. Since it would now take 150 times less long. Quote Link to comment https://forums.phpfreaks.com/topic/239371-too-many-redirects/#findComment-1229752 Share on other sites More sharing options...
redixx Posted June 14, 2011 Share Posted June 14, 2011 I can't remember the exact error, problem is i can't look at it cause then i hit a 150 request per hour limit by twitter and that makes me have to wait an hour before i can continue working. It's something that it takes to long before the site is ready loading. So once again was the error FROM twitter? If you are being limited by their API then there probably isn't anything you can do about it. For the redirect thing, it was to avoid that page loading takes to long. Since it would now take 150 times less long. How would it take 150x less time if you have to load it 150x more? Quote Link to comment https://forums.phpfreaks.com/topic/239371-too-many-redirects/#findComment-1229756 Share on other sites More sharing options...
clankill3r Posted June 14, 2011 Author Share Posted June 14, 2011 no not from twitter, and for the less time, the total time to update all 150 will be the same it just: 1: updateTweets.php --- code to update all 150 --- 2: updateTweets.php?someId=1 ---- code to update 1 +redirect to next ---- In example one after sometime i get the time error cause 60 second exceeded and the page still wan't done. In example 2, it loads a new page before it hits the time error, that's what i meant with less time. Sorry for my crappy explanation. I'm doing my best. Quote Link to comment https://forums.phpfreaks.com/topic/239371-too-many-redirects/#findComment-1229767 Share on other sites More sharing options...
redixx Posted June 14, 2011 Share Posted June 14, 2011 Ah, so you have 150 tweets to update so you were trying to load the page 150 times to do that? Haha, okay I think I gotcha. Sounds like you should be using a for loop instead. Try this: for($i=1;$i<=150;$i++) { // code to update // $i is now your $id } Quote Link to comment https://forums.phpfreaks.com/topic/239371-too-many-redirects/#findComment-1229779 Share on other sites More sharing options...
mikesta707 Posted June 14, 2011 Share Posted June 14, 2011 As far as I understand He was using a for loop... His problem is that when using a normal for loop his script was taking too long and thus going over the maximum execution time allowed by PHP. He tried to get around this by doing 1 entry per page load, but this resulted in chrome telling him the page had too many redirects. As far as your problem OP, if you have access to your PHP.ini, you could increase the maximum execution time. However, if you posted your code perhaps someone could give you pointers on making your code more efficient. I haven't used the twitter API personally, but seeing as its fairly widely used, I can't imagine that it in itself is so inefficient its causing really long execution times Quote Link to comment https://forums.phpfreaks.com/topic/239371-too-many-redirects/#findComment-1229786 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.