0

Hello,
writing a file with more than 10000 lines, cause the page never ending loading. please help me to solve it.

this is the code i have used $store contains really 10000 lines

$fp = fopen($imgpath, 'w');
fwrite($fp, $store);
fclose($fp);

After this code i have redirect script, but that is not working. but redirect script works for 2000 lines and not more than that.

Regards
Chavan

5
Contributors
17
Replies
18
Views
8 Years
Discussion Span
Last Post by cwarn23
0

It is possible that your script times out before reaching the end. You can try to use:

set_time_limit(0);

at the start of your script, to allow it to run (indefintely) until completed.

0

Hi pritaeas,

I have already used these in my program

ini_set('auto_detect_line_endings',1);
set_time_limit(0);
ini_set('post_max_size','250M');
error_reporting(0);

please any other solution.

Thanks for the reply

It is possible that your script times out before reaching the end. You can try to use:

set_time_limit(0);

at the start of your script, to allow it to run (indefintely) until completed.

0

$fp = fopen($imgpath, 'w');
fwrite($fp, $store);
fclose($fp);

Try replacing that code with the following:

file_put_contents($imgpath,$store);

A much more efficient function.

0

cwarn23,

No that too did not help me. Please problem not solved yet.

Thanks for the reply

0

Hello,

Anybody please help me in fixing this problem.

Regards
chavan

0

Try this but you will need to wait for the page to be fully loaded before you expect to see results. So try the following:

<?
set_time_limit(0);
ini_set('memory_limit','200M');
//above are the very first lines of the document

//some code in here for $imgpath and $store

if (empty($imgpath)) {
    die('invalid image path');
    }
file_put_contents($imgpath,$store);
echo 'image stored at: '.$imgpath;
0

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

0

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

0

Hi,
Any body please help me in fixing this issue. i'm really tried in trying in this issue for more than 5 days.

0

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

Edited by Reverend Jim: Fixed formatting

1

I have checked your code and although it's a bit messy and buggy, a corrected version (still messy) is as follows:

$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++)
{
$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";
}
}
if (strlen($store)==0) {
die('<h1>Store is empty!</h1>');
}
/*$fp = fopen($imgpath, 'w');
fwrite($fp, $store);
fclose($fp);*/
file_put_contents($imgpath,$store);
header("location: index.php");
Votes + Comments
thanks, writing the script, I can do, debugging, i can only ask to post the code for someone Good at it to look at
0

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

0

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.

0

Hi

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

Regards

0

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.

$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++)
{
$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";
}
}
die('<h1>$imgpath</h1>'.$imgpath.'<br><h1>$store</h1>'.$store);
/*$fp = fopen($imgpath, 'w');
fwrite($fp, $store);
fclose($fp);*/
file_put_contents($imgpath,$store);
header("location: index.php");

Also make sure $imgpath is a relative path and that the directories in it's path already exist.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.