That was very very helpful. Thanks a ton!
One more question. For every request, I am sending a redirect back to
the user and the browser takes the user to another url. The problem is
that the browser is not redirecting until the script finishes. Even if I
do flush(), the browser waits til script ends. Is there a way to force
browser to redirect and not wait for the script to end?
In Java I can think of many ways, one is to use threads, hand of data to
another thread and return the response. Another solution would be to
store data in memory (static variable) and update only after every 100
requests.
Is any of this possible in PHP?
M. Sokolewicz wrote:
Ravi wrote:
Guys, I am fairly new to PHP. Here are a few questions, if anybody can
answer it will help me get started. Thanks
I am trying to build a website and I would like to do the following in
my scripts
1. I want to return response to the browser and AFTERWARDS make a log
entry in to a database. I need this so user can experience a fast
response.
There is no "before and after". Everything you do happens during (part
of) the response. But you can just output your data, whatever it may be,
flush() it and then log it via the same script. Your user won't notice a
thing (Hell, even without the flush your user won't notice it probably).
2. If the database update fails, I want to ignore it (since it is just
log entry). Something like try-catch construct in Java. This is more
important if item1 mentioned above is not possible. Essentially
whether I make a database entry or not, I must return a valid response
to user.
So ignore it :) If you don't check for errors, you won't see them...
Makes debugging very annoying, but you won't see em nevertheless. If
your output is not based on anything from your database-update, then
there apparently is no need to worry about it.
3. Is there something like connection pool in php? Do usually people
open/close database connection for every request (I doubt that, it
sounds really slow).
There is something like that, the persistent connections (ie. via
mysql_pconnect), but generally people DO open/close connections via the
same script each and every time the script is executed (this might sound
very slow, but it's actually not too bad). Using persistent connections
is not always the best option (and usually doesn't even make much
sense); there's a good bit of documentation about it in the php docs:
http://www.php.net/manual/en/features.persistent-connections.php
Some code samples or pointers to documentation for the above would
also be very helpful.
code samples of what exactly ?
Thanks
Ravi
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php