By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,664 Members | 1,643 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,664 IT Pros & Developers. It's quick & easy.

how can i cache data that took from a txt file before?

P: n/a

Güncel : is a category name in the txt file.
BCList2.txt : data file from another site
problem : the txt file is too big. it has lots of categories in it. i
need only "Güncel" category. also it is too slow to show that category
in my page. so i want to cache it maybe in a txt file in my server. so
second time that i need the data it won't be too slow. i want to take
the data once in a day but show several times. the code below is
working as well as i need. but it is too slow to open every time
refresh my page. if any suggestions, thank you.

here is the code

<?
if (!$kategori_haber) $kategori_haber = array("Güncel");
$satir = file("http://www.ntvmsnbc.com/news/BCList2.txt") or
die("Serverla iletişim sağlanamadı!");
for ($x = 0; $x < sizeof($kategori_haber); $x++) {
for ($i = 0; $i < sizeof($satir); $i++) {
if (trim($satir[$i]) == "+$kategori_haber[$x]") {
$bas = $i + 2;
break;
}
}
for ($i = $bas; $i < sizeof($satir); $i++) {
if (substr($satir[$i], 0, 1) == "+" || $i == sizeof($satir) - 1) {
$son = $i;
break;
}
}
for ($i = $bas; $i < $son; $i++) {
$yazi = trim($satir[$i]);
if ($yazi != "-" && !eregi("$kategori_haber[$x] Güncel", $yazi)) {
$yazi = str_replace("/news/./", "http://www.ntvmsnbc.com/news/",
$yazi);
$haber_e = explode("|", $yazi);
$haber_e[0]=str_replace("http://www.ntvmsnbc.com/news/", "",
$haber_e[0]);
echo "·<font face=verdana size=1>&nbsp;<a href=\"http://
www.ntvmsnbc.com/news/$haber_e[0]\" target=_blank >$haber_e[1]</a></
font></br>\n";
}
}
}
?>

Mar 3 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On 3 Mar 2007 03:07:39 -0800, in comp.lang.php on*****@gmail.com
<11**********************@8g2000cwh.googlegroups.c omwrote:
>|
| Güncel : is a category name in the txt file.
| BCList2.txt : data file from another site
| problem : the txt file is too big. it has lots of categories in it. i
| need only "Güncel" category. also it is too slow to show that category
| in my page. so i want to cache it maybe in a txt file in my server. so
| second time that i need the data it won't be too slow. i want to take
| the data once in a day but show several times. the code below is
| working as well as i need. but it is too slow to open every time
| refresh my page. if any suggestions, thank you.
|
| here is the code
|
| <?
| if (!$kategori_haber) $kategori_haber = array("Güncel");
| $satir = file("http://www.ntvmsnbc.com/news/BCList2.txt") or
| die("Serverla ileti?im sa?lanamad?!");
| for ($x = 0; $x < sizeof($kategori_haber); $x++) {
| for ($i = 0; $i < sizeof($satir); $i++) {
| if (trim($satir[$i]) == "+$kategori_haber[$x]") {
| $bas = $i + 2;
| break;
| }
| }
| for ($i = $bas; $i < sizeof($satir); $i++) {
| if (substr($satir[$i], 0, 1) == "+" || $i == sizeof($satir) - 1) {
| $son = $i;
| break;
| }
| }
| for ($i = $bas; $i < $son; $i++) {
| $yazi = trim($satir[$i]);
| if ($yazi != "-" && !eregi("$kategori_haber[$x] Güncel", $yazi)) {
| $yazi = str_replace("/news/./", "http://www.ntvmsnbc.com/news/",
| $yazi);
| $haber_e = explode("|", $yazi);
| $haber_e[0]=str_replace("http://www.ntvmsnbc.com/news/", "",
| $haber_e[0]);
| echo "·<font face=verdana size=1>&nbsp;<a href=\"http://
| www.ntvmsnbc.com/news/$haber_e[0]\" target=_blank >$haber_e[1]</a></
| font></br>\n";
| }
| }
| }
| ?>
If this is only a daily task then I would process the data and store
it in a static html page.
---------------------------------------------------------------
jn******@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
Mar 3 '07 #2

P: n/a
on*****@gmail.com wrote:
Güncel : is a category name in the txt file.
BCList2.txt : data file from another site
problem : the txt file is too big. it has lots of categories in it. i
need only "Güncel" category. also it is too slow to show that category
in my page. so i want to cache it maybe in a txt file in my server. so
second time that i need the data it won't be too slow. i want to take
the data once in a day but show several times. the code below is
working as well as i need. but it is too slow to open every time
refresh my page. if any suggestions, thank you.

here is the code

<?
if (!$kategori_haber) $kategori_haber = array("Güncel");
$satir = file("http://www.ntvmsnbc.com/news/BCList2.txt") or
die("Serverla iletişim sağlanamadı!");
for ($x = 0; $x < sizeof($kategori_haber); $x++) {
for ($i = 0; $i < sizeof($satir); $i++) {
if (trim($satir[$i]) == "+$kategori_haber[$x]") {
$bas = $i + 2;
break;
}
}
for ($i = $bas; $i < sizeof($satir); $i++) {
if (substr($satir[$i], 0, 1) == "+" || $i == sizeof($satir) - 1) {
$son = $i;
break;
}
}
for ($i = $bas; $i < $son; $i++) {
$yazi = trim($satir[$i]);
if ($yazi != "-" && !eregi("$kategori_haber[$x] Güncel", $yazi)) {
$yazi = str_replace("/news/./", "http://www.ntvmsnbc.com/news/",
$yazi);
$haber_e = explode("|", $yazi);
$haber_e[0]=str_replace("http://www.ntvmsnbc.com/news/", "",
$haber_e[0]);
echo "·<font face=verdana size=1>&nbsp;<a href=\"http://
www.ntvmsnbc.com/news/$haber_e[0]\" target=_blank >$haber_e[1]</a></
font></br>\n";
}
}
}
?>
I agree with Jeff - if you're only using one category, create a static
page. Personally I think I'd do that with a cron job once a day to
fetch the data and build the page.

If you're looking at a lot of categories I'd recommend putting them into
a relational database such as MySQL or PostGresSQL.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Mar 3 '07 #3

P: n/a
great thanks dudes. cronning is the best way as you say.. thank you.

Mar 3 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.