parsing excel files frequently

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
devilinc
Forum Newbie
Posts: 16
Joined: Fri Nov 12, 2010 1:07 am

parsing excel files frequently

Post by devilinc »

my issue got to do with parsing excel files frequently….
no frameworks used, only PHP
there is a category and a sub-category….
if a user logs in to the site, if he clicks on category, some information stored in excel files will be displayed to the user…...also the category has sub-category where he can see more information which is stored in other excel files….since this is time consuming to pull data from excel files which is stored in database each time the user views it is there a mechanism like where he can pull out the excel file and let the excel file remain in memory, so that he gets information faster? hope it is clear enough….
devilinc
Forum Newbie
Posts: 16
Joined: Fri Nov 12, 2010 1:07 am

Re: parsing excel files frequently

Post by devilinc »

so here is what i found my reading that file_get_contents() does help in retreiving file contents and acting as primary memory but it writes the entire file to string which is not very useful....i used sessions here and checked if the session is unset before closing the file? is it close enough or do we have better ideas???
User avatar
saltwine
Forum Newbie
Posts: 16
Joined: Tue Nov 09, 2010 7:05 am
Location: London

Re: parsing excel files frequently

Post by saltwine »

Hi devilinc


Is the data in the Excel files static, or infrequently changed? If so, you might want to consider some sort of caching functionality. A good open source library available can be found at http://www.memcached.org.

Alternatively, you could write a very simple PHP function, something like what's below, to query your database and store the results on the file system:

Code: Select all

<?php
// start the output buffer
ob_start(); ?>

// your usual PHP script and HTML here...

$cachefile = "cache/category1.html";

// open the cache file "cache/category1.html" for writing
$fp = fopen($cachefile, 'w'); 

// save the contents of output buffer to the file
fwrite($fp, ob_get_contents()); 

// close the file
fclose($fp); 

// Send the output to the browser
ob_end_flush(); 
?>
And then something like this to retrieve the cache file, and improve performance:

Code: Select all

<?php
$cachefile = "cache/category1.html";

if (file_exists($cachefile)) {
	// the page has been cached from an earlier request
	// output the contents of the cache file
	include($cachefile); 
}
?>
devilinc
Forum Newbie
Posts: 16
Joined: Fri Nov 12, 2010 1:07 am

Re: parsing excel files frequently

Post by devilinc »

well actually those files are csv files and so i output the contents in different places based on the conditions, description fields etc....is it possible to do some formatting for the files stored in memcache? i use a filereader and csv reader files which i got it downloaded from net to help in file operations......file reader had this close() where i did i simple check to see if session is unset, if its not dont proceed to the close()....i think u got a better idea how it is implemented in mine now....
devilinc
Forum Newbie
Posts: 16
Joined: Fri Nov 12, 2010 1:07 am

Re: parsing excel files frequently

Post by devilinc »

thanks for popping in with ur idea...and hoping for more after u read my post....
Post Reply