fopen extremely slow

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

bountyhunter
New php-forum User
New php-forum User
Posts: 6
Joined: Sat Mar 22, 2003 9:41 am

fopen extremely slow

Postby bountyhunter » Sat Mar 22, 2003 9:49 am

Hi,

I've written a PHP script which grabs data from a webpage to store on my webserver. This script works for fine except for one particular url where is takes around 3-5 minutes to execute (on occasions it times out).

The code which is causing the delay is:

$remotefilehandle = fopen($remotefile,"r")

where $remotefile is "http://www.betbrain.com/front.jsp?site=9"

If you put this url in a browser, the page displays in a couple of seconds, so why does fopen() take up to 5 minutes?

User avatar
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby Oleg Butuzov » Sat Mar 22, 2003 11:50 pm

URL!

bountyhunter
New php-forum User
New php-forum User
Posts: 6
Joined: Sat Mar 22, 2003 9:41 am

Postby bountyhunter » Sun Mar 23, 2003 2:37 am


User avatar
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby Oleg Butuzov » Sun Mar 23, 2003 3:44 am

you did not understud me.

you try to open URL so it always will be slow.
i think you are newbee. Am I right?

bountyhunter
New php-forum User
New php-forum User
Posts: 6
Joined: Sat Mar 22, 2003 9:41 am

Postby bountyhunter » Sun Mar 23, 2003 6:43 am

I may be a newbie, but why do all other url's i open using this script take 2-3 SECONDS, and this particular url take 5 MINUTES!!!!

This does not make sense.

User avatar
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby Oleg Butuzov » Sun Mar 23, 2003 6:49 am

5 minutes???? :D

bountyhunter
New php-forum User
New php-forum User
Posts: 6
Joined: Sat Mar 22, 2003 9:41 am

Postby bountyhunter » Sun Mar 23, 2003 8:07 am

Yes, exactly!

The script works, and the fact that it takes so long is not a major problem, because it is a scheduled script that runs every 20 minutes on the webserver, but i would like to know why it takes so long.

Xerpher
New php-forum User
New php-forum User
Posts: 164
Joined: Tue Aug 27, 2002 8:25 pm
Location: Ontario, Canada
Contact:

Postby Xerpher » Sun Mar 23, 2003 5:42 pm

http://www.betbrain.com/front.jsp?site=9 Loaded instantly for me, while http://www.betonsuccess.com/php/betbrainvaluebets.php Just never loaded at all (Waited 15 minutes)

User avatar
Skeletor
New php-forum User
New php-forum User
Posts: 147
Joined: Tue Nov 19, 2002 7:47 am
Location: US, Ohio
Contact:

Postby Skeletor » Mon Mar 24, 2003 5:49 am

I haven't tried it myself, and not sure if this is the answer, but...

on the romote server that contains the page your trying to open, is the allow_url_fopen option enabled? php.net says it will stop some pages from being opened with fopen if this property is not enabled on their server.

Not sure if it's the answer, but is worth check out perhaps.

good luck.

User avatar
Skeletor
New php-forum User
New php-forum User
Posts: 147
Joined: Tue Nov 19, 2002 7:47 am
Location: US, Ohio
Contact:

Postby Skeletor » Mon Mar 24, 2003 6:19 am

I used the following code:

<?php
$fp = fopen("http://www.betbrain.com/front.jsp?site=9","r");
while(!feof($fp)) {
$buffer = fgets($fp,4096);
echo $buffer;
}
fclose($fp);
?>

The page to it is:
http://www.bivrip.com/devel/fopen.php

the problem may be within the rest of your code perhaps?

bountyhunter
New php-forum User
New php-forum User
Posts: 6
Joined: Sat Mar 22, 2003 9:41 am

Postby bountyhunter » Mon Mar 24, 2003 6:45 am

I've commented out the rest of my script to confirm that the fopen is responsible for the 5 minute delay.

The only difference between my script and yours is that i am reading the whole file at once, whereas you are reading a small buffer. I will try your solution in my script to see if it "fixes" it.

bountyhunter
New php-forum User
New php-forum User
Posts: 6
Joined: Sat Mar 22, 2003 9:41 am

Postby bountyhunter » Mon Mar 24, 2003 6:55 am

It worked!

5 minutes down to 3 seconds! Thanks :D


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 1 guest

cron