Re: More info on timeout problem, with code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 11/5/07, Jon Westcot <jon@xxxxxxxxxxx> wrote:

> Hi all:
>
>    As requested, here's the code:
>
> <?php
> if(isset($_POST['process'])){
>    $old_session_gc_maxlifetime = "";
>    $old_max_execution_time = "";
>    $old_max_input_time = "";
>    $old_session_gc_maxlifetime = ini_set("session.gc_maxlifetime","1800");
>    $old_max_execution_time = ini_set("max_execution_time","1800");   // 30
> minutes
>    $old_max_input_time = ini_set("max_input_time","1800");   // 30
> minutes -- doesn't work
>
>    echo "<p>Session.gc_maxlifetime: " . ini_get("session.gc_maxlifetime")
> .
> "</p>\n";  // shows 1800
>    echo "<p>Max execution time: " . ini_get("max_execution_time") .
> "</p>\n";  // shows 1800
>    echo "<p>Max input time:     " . ini_get("max_input_time") . "</p>\n";
> // shows -1
>
>    ignore_user_abort(TRUE);
>    set_time_limit(0);
>
>    $query = mysql_query("TRUNCATE evall;");

                                                                ^
>From The Manual...
**
*mysql_query*

A SQL query

The query string should ___not___ end with a semicolon.



>    echo "<p>Results of Truncate: $query</p>\n";
>
>    $myfile_replace = "uploads/evall.csv";
>    $handle = @fopen($myfile_replace, 'rb');
>    $save_handle = @fopen("tmp/sql_calls.txt", "wb");
>
>    $process_count = 0;
>    if(!$handle) {
>        echo "<p>The file ($myfile_replace) could not be opened.<br
> /></p>\n";
>        flush();
>    } else {
>        echo "<p>The file ($myfile_replace) opened correctly.<br /></p>\n";
>        flush();
>
>        $headings = fgetcsv($handle, 10000, ",");  // Just ignore the first
> row returned.
>        $row = 0;
>        while (($data = fgetcsv($handle, 10000, ",")) !== FALSE) {
>            $row++;
>            $num = count($data);
>            $insert_query = "INSERT INTO evall VALUES(";
>            for ($c=0; $c < $num; $c++) {
>                if($c > 0) {
>                    $insert_query .= ",";
>                }
>                $insert_query .= '"' . $data[$c] . '"';
>            }
>            $insert_query .= ");";
>
>            if(fwrite($save_handle, $row . "; " . strlen($insert_query) .
> ":
> " . "\n") === FALSE) {
>                echo "<p>The query could not be written.</p>\n";
>            } else {
>                $process_count++;
>            }
>            if($row % 1000 == 0) {
>                echo "$row records processed so far<br />\n";
>                flush();
>            }
>        }
>        echo "<p>File import completed. $row records read; $process_count
> records added.</p>\n";
>        flush();
>        fclose($save_handle);
>        fclose($handle);
>    }
>
>    ini_set("session.gc_maxlifetime",$old_session_gc_maxlifetime);
>    ini_set("max_execution_time",$old_max_execution_time);
>    ini_set("max_input_time",$old_max_input_time);
>
> }
> ?>
> <form name="form" enctype="multipart/form-data" action="<?php echo
> $_SERVER['PHP_SELF']; ?>" method="POST" >
>    <p>Version 1.9 -- The file uploading process presupposes that the user
> has uploaded the EVAll.CSV
>    file to the &quot;uploads&quot; folder. If this has been done and
> you're
> ready to process
>    it, click the &lt;Process&gt; button.</p>
> <input type="submit" name="process" value="Process" /><br/><br/>
> </form>


hth,

David

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux