Forum Moderators: coopster
While experimenting with some code, I found the sleep() function, so I decided to try it out.
After a bunch of lines of code I called
sleep(5);
and then wrote some more code after this line just to test it's behaviour. So I was expecting the script to be executed as usual until it found the sleep function, then wait 5 seconds and continue execution. Like some of you might know, this did not happen.
The script waited 5 seconds and then spat everything at once to the browser. How is this?
The reason is that I am working in a script to update my database. The script does the following:
1. Connects to de db
2. Opens a csv file and loads it into a temporary table (t1)
3. Creates another temporary table (t2) and inserts some columns and records from t1 (i am not interested in all of them)
4. Truncates my "live" table.
5. Inserts the values from t2 into my "live" table.
The reason I did this is because it takes too long for the script to process the csv file, that contains some 60,000 records x 22 fields.
What I want the scrip to do is to process the file, extract the records I am interested in (some 3,000) and only after this is done, delete the table that is been accesed by users.
However, this would only make sense if the script executes one step at a time. If not, my live table is going to be empty for about 3 minutes, which is how long the scipt takes to finish.