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

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.

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.

Just wondering, why are you writing 10000 lines into a file?

$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.

cwarn23,

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

Thanks for the reply

Hello,

Anybody please help me in fixing this problem.

Regards
chavan

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;

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

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

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

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

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");
commented: thanks, writing the script, I can do, debugging, i can only ask to post the code for someone Good at it to look at +3

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

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.

Hi

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

Regards

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.