![]() |
![]() |
![]() |
||||
Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
Damn Right I Kiss Ass!
Industry Role:
Join Date: Dec 2003
Location: Cowtown, USA
Posts: 32,409
|
PHP advice on loops
I need to create a loop that do something.
If that something fails to happen, I need the loop to go back and do it again until it happens... The basic: top: Get a URL that may timeout; (if URL isn't grabbed) -> goto top; My current understanding of loops in PHP can't figure out this kind of loop. Where it will keep going back into infinity when the if match isn't being met. Anyone? |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 |
So Fucking Banned
Join Date: Aug 2003
Location: ICQ #23642053
Posts: 19,593
|
lookup 'while' on php.net
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 |
Confirmed User
Join Date: Aug 2003
Posts: 1,798
|
do you mean something like this?
do { $fp = fopen($url,'r'); $fout = ''; while ($s=fgets($fp,1000)) { $fout .= $s } fclose($fp); } while (empty($fout));
__________________
TGP Webmasters: sign up for the top 100 tgp list! Submit galleries If you add me to icq (title) make sure to mention GFY or I'll think you're a bot and deny you. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 |
Confirmed User
Join Date: Sep 2004
Location: PA, USA
Posts: 5,283
|
I know very little PHP, but from what I understand this is the correct structure:
PHP Code:
__________________
- David Hall ICQ: 312744199 |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#5 |
Confirmed User
Join Date: Sep 2004
Location: PA, USA
Posts: 5,283
|
Ok, I was no help at all haha
__________________
- David Hall ICQ: 312744199 |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#6 |
Damn Right I Kiss Ass!
Industry Role:
Join Date: Dec 2003
Location: Cowtown, USA
Posts: 32,409
|
I am using cURL wrapped inside a function to get data from a URL... If it times out, I need it to ask for the data again. and again, until the function returns the data I want.
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#7 |
Confirmed User
Join Date: Dec 2004
Location: NL (Eindhoven), CZ(Prague), FR(Concarneau)
Posts: 3,958
|
Argf, hate when you gets tuck with php. I'm stuck too right now with an AJAX Live search script.
![]() Gets results fine but i can't research without refreshing the page...
__________________
[img]http://****************/sig/fhv3_j2_624x80_2.gif[/img] $35-40 Per Signup, 60-70% Rev Share, over 80 Sites, Exclusive Sites, tons of free content 14,000+ Free hosted Galleries, RSS feeds, Domain Hosting, Embedded Flash Movies Join Fetish Hits now! ICQ: 358652230 |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#8 | |
So Fucking Banned
Join Date: Aug 2003
Location: ICQ #23642053
Posts: 19,593
|
Quote:
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#9 |
Confirmed User
Join Date: Dec 2004
Location: NL (Eindhoven), CZ(Prague), FR(Concarneau)
Posts: 3,958
|
Haha, yes!!! I solved my problem
![]() ![]() function handleHttpResponse() { if (http.readyState hahahaha 4 && http.status hahahaha 200) { document.getElementById('results').innerHTML = http.responseText; done = false; } }
__________________
[img]http://****************/sig/fhv3_j2_624x80_2.gif[/img] $35-40 Per Signup, 60-70% Rev Share, over 80 Sites, Exclusive Sites, tons of free content 14,000+ Free hosted Galleries, RSS feeds, Domain Hosting, Embedded Flash Movies Join Fetish Hits now! ICQ: 358652230 |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#10 | |
Confirmed User
Join Date: Aug 2003
Posts: 1,798
|
Quote:
do { grab your url with curl } while (url hasnt been gotten); is the basic concept/syntax
__________________
TGP Webmasters: sign up for the top 100 tgp list! Submit galleries If you add me to icq (title) make sure to mention GFY or I'll think you're a bot and deny you. |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#11 |
Damn Right I Kiss Ass!
Industry Role:
Join Date: Dec 2003
Location: Cowtown, USA
Posts: 32,409
|
Nice Sam... now...
The thing I guess I am not grasping is that the while statement is going to have to call the funtion in question and the check to see if it worked seems to come before that... hmm... OK, got it... Fuck.. talk about hammering a server... |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#12 |
Confirmed User
Join Date: Nov 2005
Posts: 647
|
why aren't you using a cron? what happens if the server is down and your script sits in a continuous loop until it eats enough memory to crash the box?
__________________
money talks and bullshit walks. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#13 | |
Damn Right I Kiss Ass!
Industry Role:
Join Date: Dec 2003
Location: Cowtown, USA
Posts: 32,409
|
Quote:
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#14 |
Confirmed User
Join Date: Jan 2003
Location: San Jose
Posts: 548
|
!!! Just a thought !!!
Maybe you should cache the results locally get the time before you enter a loop, (while loop or whatever doesn't matter) loop in it making your read requests, if you don't make the read in x amount of seconds, (1 sec would be a max time for me) read the cached local content. It is very hard on your server to hang up apache on these long processes, I'd only read remotely if i had to. If it is a news feed or something you can get away normally with only having to read this in once or twice a day. The rest of the time reading from the local cached file you created. In addition if you are pharsing the information you are reading in. Cache it in the form of already being pharse as pharsing is an expensive process as well. If this site gets any type of traffic, a code written in such a way to keep trying if even for only 3 - 5 seconds could bring the server to its knees. So you need to think of other ways to achive your end result. With apache you only have so many processes you can use, generally around 250 apache processes on a server. After this, or close to this number you'll stop serving pages, aka loose your ass on your money. Long connection times can really cause this number to go much higher than needed and even spiral out of control, in general it's a really bad idea. As mentioned by others if it keeps trying and you have no memory limit set and no script execution time set, the script could (and in my opinion at some time will) crash your server. In addition about 'sleeping' in your php scripts this produces the above results, which are very harmful to your server. There is no reason to sleep in your php. I don't know what problem you have, but you need to take a different look at it as what i see written here will not scale at all, and will greatly harm your server. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#15 | |
Registered User
Join Date: Nov 2005
Posts: 17
|
Quote:
![]() ![]() ![]() |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#16 | |
Damn Right I Kiss Ass!
Industry Role:
Join Date: Dec 2003
Location: Cowtown, USA
Posts: 32,409
|
Quote:
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#17 |
sex dwarf
Join Date: May 2002
Posts: 17,860
|
If this is a mission-critical script, one piece of advice: don't do it yourself. Stuff like this, when done wrong, is exactly what causes huge server load, infinite loops, dead pages, etc. It seems to me that you aren't very experienced in PHP yet, so if you aren't just doing this as some exercise but as something essential to one of your sites, getting a real programmer is probably a good idea.
__________________
/(bb|[^b]{2})/ |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#18 | |
Damn Right I Kiss Ass!
Industry Role:
Join Date: Dec 2003
Location: Cowtown, USA
Posts: 32,409
|
Quote:
![]() This server in question BTW will not be dead on the amount of traffic it is getting... |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#19 | ||
sex dwarf
Join Date: May 2002
Posts: 17,860
|
Quote:
You said: Quote:
__________________
/(bb|[^b]{2})/ |
||
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#20 | |
Damn Right I Kiss Ass!
Industry Role:
Join Date: Dec 2003
Location: Cowtown, USA
Posts: 32,409
|
Quote:
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |