Forum Moderators: coopster

Message Too Old, No Replies

Optimizing data writing

Data writing independent of page displaying

         

Tastatura

12:48 am on Mar 28, 2006 (gmt 0)

10+ Year Member



Hi all,
My question has to do with writing data to the db – I know that I can have a routine to open db connection, write data, etc, however I would like to do this in parallel, or actually independent of page content loading and displaying. Basically I don’t want user to wait on content to be displayed while data is being written to db (i.e. I see this as two independent ‘operations’ and don’t want to couple them if that will affect page display time).
What is the best way to do this using PHP?
Using ‘fork’? Or calling writing routine after </html> tag? Or…

Thanks

Tastatura

5:02 pm on Mar 28, 2006 (gmt 0)

10+ Year Member



bumpy. Anyone?

Tastatura

5:43 pm on Mar 28, 2006 (gmt 0)

10+ Year Member



I should of prefixed my original post with this so that it (hopefully) makes more sense:

I was wondering if anyone has the opinion what is the best way to optimize page load time in the following scenario (maybe this is trivial however I am new to PHP…):
-(page is being created using PHP)
-some (user) data has been collected and I want to store it to db
-page content should be loaded and displayed to the user

barns101

5:43 pm on Mar 28, 2006 (gmt 0)

10+ Year Member



At first I was going to say just add the code after </html> but on second thoughts I think the PHP code may be executed by the server (i.e. add data to database) BEFORE serving the plain HTML content to the browser anyway. (So the visitor would have to wait either way.)

Anyone confirm?

coopster

6:03 pm on Mar 28, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I usually want to make sure the content was written to the database successfully before I send them onto the next display. Often times the next display is dependent upon a successful/unsuccessful operation.

Tastatura

6:13 pm on Mar 28, 2006 (gmt 0)

10+ Year Member



Often times the next display is dependent upon a successful/unsuccessful operation.

I agree that this is true n most cases. But what if data that has been collected, and that needs to be written is, for example, is used only by me for statistical purposes. Or maybe in more general terms, data that has been collected will not be used for anything displayed to the user on the next page. In that case, I don’t want to delay page being displayed to the user due to writing to db. Is this possible using PHP?

barns101

7:33 pm on Mar 28, 2006 (gmt 0)

10+ Year Member



Unless there's a reason to believe that your query will take a long time I don't think it would affect page load times noticeably.

Tastatura

1:50 am on Mar 29, 2006 (gmt 0)

10+ Year Member



Thank you to everyone for the info. I am still not clear if 'pcntl_fork' can be used to do this...
ref [php.net ]