Forum Moderators: coopster

Message Too Old, No Replies

How is a php file parsed?

         

alce

9:50 pm on May 15, 2006 (gmt 0)

10+ Year Member



I am a bit confused with the way a php script is executed.

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?

eelixduppy

9:58 pm on May 15, 2006 (gmt 0)



try adding flush(); [us3.php.net] to the script right before the sleep() function.

eelix

alce

11:17 pm on May 15, 2006 (gmt 0)

10+ Year Member



I had a look to flush(), thank you. However, I do not really need to use the sleep() function. I want to understand how the interpreter reads and executes the code.

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.

coopster

12:18 am on May 16, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Maybe a different approach is required. How about using a temporary table. Copy the original, do your work on the copy, rename the original and finally name the "working" copy as the original name again. Should be much much quicker. Just an idea ...

alce

12:34 am on May 16, 2006 (gmt 0)

10+ Year Member



That is actually a good idea. Instead of deleting the working table, just renaming both tables.

However, if the script behaves like the one I had the sleep() function in, it is going to rename the working table before the rest of the process is done...we will see, said a blind man.