Skip to content

SplFileObject very high disk usage #17379

@Red-Owl

Description

@Red-Owl

Description

// use fseek

<?php
set_time_limit(0);
![disk](https://github.com/user-attachments/assets/f02f3400-3645-4a8f-9be4-b9bf3c6dfa49)



echo "loading";
$filepath = "Video Music.txt";

$file = new SplFileObject($filepath);
$n = 0;
$lined = Array();
$data1 = Array();
$datar = "";



$file_sql = $filepath.'.sql';
// The new person to add to the file

// Write the contents to the file, 
// using the FILE_APPEND flag to append the content to the end of the file
// and the LOCK_EX flag to prevent anyone else writing to the file at the same time

$link = mysqli_connect('127.0.0.1', 'wlab', 'xxxxxx', 'test', '3307');
if (!$link) {
    die('Not connected : ' . mysql_error());
}

// make foo the current db
/* $db_selected = mysqi_select_db('torrent', $link);
if (!$db_selected) {
    die ('Can\'t use foo : ' . mysql_error());
}
*/


while (false !== ($char = $file->fgetc())) {
    //echo "$char\n";
    $n++;
    $lined[] = $char;
    if($char == "\n"){
        $datar = implode('', $lined);
        $data1 = explode("|", $datar);
        if(count($data1)==2){
        $sql = "INSERT INTO magnet SET mn_exid=NULL,mn_name='".addslashes($data1[1])."',mn_size=NULL,mn_seed=NULL,mn_leker=NULL,mn_magnet='".trim($data1[0])."', mn_categ='".basename($filepath)."', mn_origin='BitSnoop', mn_date='2012-02-12 00:00:00';\r\n";
        // echo "\n<br />"
        // file_put_contents($file_sql, $sql, FILE_APPEND | LOCK_EX);
        mysqli_query($link,$sql);
    }else{
            echo $datar; 
        }
        $datar = ""; 
        $lined = Array();
    }
    /* if($n==5000){
        exit;
    } */
 
}


echo $n;

?>

### PHP Version

 8.3.12 

### Operating System

win 11

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions