Forum Moderators: coopster

Message Too Old, No Replies

read multiple files

         

omax

9:05 am on Jun 15, 2007 (gmt 0)

10+ Year Member



Hi
I have a PHP script where I read parts of xml feeds from multiple web addresses and display data.
Something like :

for(){
$filedata = @file(url);
parse xml -> display data
}

My problem : can I read more files at once (multithreading?) - because it seems to work very slow now.

Thanks.

omoutop

10:13 am on Jun 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Haven't try it before, but since you read your file and put it's content into an array, it seems logical to be able to add more data into the same array by reading more files.

later you can arrange data to appear in differet way.

omax

10:24 am on Jun 15, 2007 (gmt 0)

10+ Year Member



It's not what I want - I want to read the files I need -http://domain1/file1, http://domain2/file2 etc - simultaneously. - so the main page will load faster.

[edited by: eelixduppy at 2:06 pm (utc) on June 15, 2007]
[edit reason] delinked [/edit]

jatar_k

12:54 pm on Jun 15, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>> simultaneously

no you can't

anytime you are reading from a url there are many things that could make it slow, you are relying on another site plus all connections in between

if you want to speed it up then read it in the background via cron, or something, then save it somewhere, then just include that data on the main page

omax

1:32 pm on Jun 15, 2007 (gmt 0)

10+ Year Member



ok - and how to use the cron for my needs? I'm not an expert ....

For example I want data from 10 URLs. Should I have the php script and call it via cron?

jatar_k

1:35 pm on Jun 15, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I was thinking you could have a cron that grabs the data from your 10 feeds, run every 15 mins or something

so you build a php script, which is executed via cron, that parses the feeds and saves them to a file, your main page can then include the file in the appropriate location on the page

omax

7:40 pm on Jun 15, 2007 (gmt 0)

10+ Year Member



ok - thank you - I'll try