Re: multiple visitors at the same time [message #182983 is a reply to message #182979] |
Tue, 01 October 2013 00:13 |
Lew Pitcher
Messages: 60 Registered: April 2013
Karma:
|
Member |
|
|
On Monday 30 September 2013 18:12, in comp.lang.php, "richard"
<noreply(at)example(dot)com> wrote:
> I kind of realized i now have another problem to deal with.
> As I have it set up, when a visitor enters, that creates a playlist for
> that visitor.
> What happens when another visitor is online?
> I tried it with both IE and FF at the same time.
> While the list is dffierent, there is no audio in the second browser.
>
> So I figure I will have to give each browser a unique id to the playlist.
> But how?
At the beginning of the webpage, before /anything/ has been sent to the
client, have your PHP code execute a session_start() call. Note that this
*absolutely must* be the first thing done; if you send out even one blank
line, this does not work.
session_start() generates a cookie, records the cookie identifier on the
server side, and sends the cookie to the client in the HTTP headers.
Because the cookie has to go out in the headers, you cannot send any data
before it.
Now, in your page's body PHP, you can test certain values that PHP provides
that all relate to that cookie. The easiest way is to check the existance
and contents of the $_SESSION associative array.
$_SESSION will be null (as will any keyed $_SESSION value) on the client's
initial entry to the page. Thus, an isset() test within the body will be
able to determine if the client has retrieved the initial page, or has
retrieved a second or subsequent time.
As $_SESSION is an associative array, you can store values in it. Each time
the client returns and rereads the page, you get the values /for that
client/ as values of $_SESSION.
So, your logic might look something like
if (isset($_SESSION['RowNum'])
{
/* RETURNING CLIENT
$_SESSION['RowNum'] is last row shown to the client, so
start his listing at database result row (1 + $_SESSION['RowNum'])
*/
$StartRow = 1 + $_SESSION['RowNum'];
/* generate next result set, from row $StartRow to $EndRow */
$_SESSION['RowNum'] = $EndRow;
}
else
{
/* NEW CLIENT
$_SESSION['RowNum'] is not set.
start his listing at database result row 0
*/
$StartRow = 0;
}
$EndRow = ComputeEndRow($StartRow);
GeneratePartialResultSet($StartRow, $EndRow);
/* save the session's start row for next time */
$_SESSION['RowNum'] = $EndRow;
.....
> Would the server crash with s few thousand visitors online at the same
> time?
It depends on how you've configured your server. If you have your http
server set up to handle a large number of connections, and enough temporary
space for a large number of session state records (saved as small files),
and have configured the database server for the large number of database
connections, you should have no problem servicing thousands of simultaneous
clients.
[snip].
--
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request
|
|
|