PHP - *fast* serialize/unserialize?

前端 未结 8 1757
死守一世寂寞
死守一世寂寞 2021-02-19 04:54

I have a PHP script that builds a binary search tree over a rather large CSV file (5MB+). This is nice and all, but it takes about 3 seconds to read/parse/index the file.

<
8条回答
  •  再見小時候
    2021-02-19 05:14

    var_export should be lots faster as PHP won't have to process the string at all:

    // export the process CSV to export.php
    $php_array = read_parse_and_index_csv($csv); // takes 3 seconds
    $export = var_export($php_array, true);
    file_put_contents('export.php', '');
    

    Then include export.php when you need it:

    include 'export.php';
    

    Depending on your web server set up, you may have to chmod export.php to make it executable first.

提交回复
热议问题