943,908 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1052
  • PHP RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Aug 24th, 2009
0

Re: infinite loads while writing a file with more than 10000 lines

Click to Expand / Collapse  Quote originally posted by chavansoft ...
cwarn23,

I tried it but still could not solve the problem. please I'm trying with all soughts of different function but could not fix it. Please help me.

Thank you for the Reply

Regards
chavan
perhaps post a little more of the code, the balls up could be the combination of another bottleneck with this one
Reputation Points: 562
Solved Threads: 368
Posting Maven
almostbob is offline Offline
2,970 posts
since Jan 2009
Aug 26th, 2009
0

Re: infinite loads while writing a file with more than 10000 lines

Hi,
Any body please help me in fixing this issue. i'm really tried in trying in this issue for more than 5 days.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
chavansoft is offline Offline
15 posts
since Aug 2009
Aug 26th, 2009
0

Re: infinite loads while writing a file with more than 10000 lines

Click to Expand / Collapse  Quote originally posted by almostbob ...
perhaps post a little more of the code, the balls up could be the combination of another bottleneck with this one
almostbob,

This is the complete code in the post of my form, please help me in solving this issue. the program is not getting redirected with large number of lines

here is the code you asked for
$list = file_get_contents($imgpath);
$listarray = array();
$listarray = explode("\n",$list);
$count_line = count($listarray);


$key = array();
$newline ='';
$store ='';
for($i =0; $i <= count($listarray) ; $i++)
{
if($i == count($listarray))
{

/*$fp = fopen($imgpath, 'w');
fwrite($fp, $store);
fclose($fp);*/
file_put_contents($imgpath,$store);
header("location: index.php");


}
$name = $listarray[$i];

// Replaces the Empty Line
$line = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", '', $name);
$line = trim($line);
if($line !='')
{
// Apply URL

$line = link($line);

$fault =0;
$key[] = $line;
$store .= trim($line)."\r\n";
}
}

Regards
Last edited by chavansoft; Aug 26th, 2009 at 7:43 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
chavansoft is offline Offline
15 posts
since Aug 2009
Aug 27th, 2009
1

Re: infinite loads while writing a file with more than 10000 lines

I have checked your code and although it's a bit messy and buggy, a corrected version (still messy) is as follows:
php Syntax (Toggle Plain Text)
  1. $list = file_get_contents($imgpath);
  2. $listarray = array();
  3. $listarray = explode("\n",$list);
  4. $count_line = count($listarray);
  5.  
  6.  
  7. $key = array();
  8. $newline ='';
  9. $store ='';
  10. for($i =0; $i <= count($listarray) ; $i++)
  11. {
  12. $name = $listarray[$i];
  13.  
  14. // Replaces the Empty Line
  15. $line = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", '', $name);
  16. $line = trim($line);
  17. if($line !='')
  18. {
  19. // Apply URL
  20.  
  21. $line = link($line);
  22.  
  23. $fault =0;
  24. $key[] = $line;
  25. $store .= trim($line)."\r\n";
  26. }
  27. }
  28. if (strlen($store)==0) {
  29. die('<h1>Store is empty!</h1>');
  30. }
  31. /*$fp = fopen($imgpath, 'w');
  32. fwrite($fp, $store);
  33. fclose($fp);*/
  34. file_put_contents($imgpath,$store);
  35. header("location: index.php");
Sponsor
Featured Poster
Reputation Points: 410
Solved Threads: 258
Occupation: Genius
cwarn23 is offline Offline
3,004 posts
since Sep 2007
Aug 27th, 2009
0

Re: infinite loads while writing a file with more than 10000 lines

cwarn23,

I tried this before, it did not work, for that reason i have changed it into the new one , which i have posted already.

Thanks for the reply, Help me fix this, please
Reputation Points: 10
Solved Threads: 0
Newbie Poster
chavansoft is offline Offline
15 posts
since Aug 2009
Aug 28th, 2009
0

Re: infinite loads while writing a file with more than 10000 lines

Did you try my version anyway because I added 3 lines you wouldn't have had before and see if the page ends early with an error message telling you the problem.
Sponsor
Featured Poster
Reputation Points: 410
Solved Threads: 258
Occupation: Genius
cwarn23 is offline Offline
3,004 posts
since Sep 2007
Aug 31st, 2009
0

Re: infinite loads while writing a file with more than 10000 lines

Hi

Thank you, I forgot that three lines. But it doesn't work. what am I suppose to do

Regards
Reputation Points: 10
Solved Threads: 0
Newbie Poster
chavansoft is offline Offline
15 posts
since Aug 2009
Sep 1st, 2009
0

Re: infinite loads while writing a file with more than 10000 lines

If the error saying "store is empty" did not trigger then I would suggest checking what those two variable contain. So run the following code to make sure that the variables are set correctly.
php Syntax (Toggle Plain Text)
  1. $list = file_get_contents($imgpath);
  2. $listarray = array();
  3. $listarray = explode("\n",$list);
  4. $count_line = count($listarray);
  5.  
  6.  
  7. $key = array();
  8. $newline ='';
  9. $store ='';
  10. for($i =0; $i <= count($listarray) ; $i++)
  11. {
  12. $name = $listarray[$i];
  13.  
  14. // Replaces the Empty Line
  15. $line = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", '', $name);
  16. $line = trim($line);
  17. if($line !='')
  18. {
  19. // Apply URL
  20.  
  21. $line = link($line);
  22.  
  23. $fault =0;
  24. $key[] = $line;
  25. $store .= trim($line)."\r\n";
  26. }
  27. }
  28. die('<h1>$imgpath</h1>'.$imgpath.'<br><h1>$store</h1>'.$store);
  29. /*$fp = fopen($imgpath, 'w');
  30. fwrite($fp, $store);
  31. fclose($fp);*/
  32. file_put_contents($imgpath,$store);
  33. header("location: index.php");
Also make sure $imgpath is a relative path and that the directories in it's path already exist.
Sponsor
Featured Poster
Reputation Points: 410
Solved Threads: 258
Occupation: Genius
cwarn23 is offline Offline
3,004 posts
since Sep 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: How to use this function FillList ($sql, $selected=0)
Next Thread in PHP Forum Timeline: string comparsion





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC