user1593979
user1593979

Reputation:

Need to prevent parsing a huge CSV file repeatedly in PHP

I have a huge a CSV file which I parse to store the data in a PHP array. For different PHP files I have to parse it again and again to store it in the array. How can I prevent this by storing it in array and then have this array available to all PHP files?

Upvotes: 1

Views: 131

Answers (3)

Ariel
Ariel

Reputation: 26753

apc_cache() is what you want. http://us.php.net/manual/en/function.apc-fetch.php

Upvotes: 2

uınbɐɥs
uınbɐɥs

Reputation: 7341

Store the array in a file using serialize:

file_put_contents('file.txt', serialize($data));

Then when you need to access it again, use unserialize:

$data = unserialize(file_get_contents('file.txt'));

Upvotes: 0

Igor Parra
Igor Parra

Reputation: 10348

You can write it to a file. Use serialize() before. Then include the file each time you need it (include_once):

$my_csv_data = serialize($data);

Upvotes: 0

Related Questions