I don't know what you want to achieve, but changing the set_time_limit is often not recommended. This can lead to an ever running script, and if you call the script every x hours will crash you server in some time.
But as I understand you want to generate a csv file for an user. What you do now is (I guess) an user goes to a link and you start rendering the csv.
What you could do (using javascript) is that when you click the link there starts a progressbar, and you start rendering the file in the background (can even send an email when finished). This way the user can still use the system, also the user won't press reload so you start rendering multiple csv.
Second, I don't know the codeigniter
framework, native functions are always faster. But if you need to render 1.000+ rows perhaps you can look into sharing the load. So load 100, insert 100 rows, load 100, insert 100 .... (you get the point I hope) (100 is just a number)
Hope this tips can help
edit --- some code example ---
Well it took some time but here is some code examples of the above.
First we will check every x seconds (i do 60 in the example)(so every min) if the csv exists. To check if the file exists we use this stackoverflow anser and just add a simple javascript interval.
var checkFile = self.setInterval(function(){checkFile()},60000); // interval uses milli seconds as far as I know
function checkFile() {
if (UrlExists(url)) { // url exists is the function of the answer given
checkFile = window.clearInterval(checkFile);
// add other stuff to do
}
}
With this code you can check if the file is renderd and if so, you can set a message to the user or something else