php-general Digest 20 Aug 2010 09:49:43 -0000 Issue 6903

Topics (messages 307582 through 307596):

Re: imagettftext Angle Problem
        307582 by: Bborie Park

[OUTPUT BUFFER] - problems with redirects
        307583 by: Tristan
        307585 by: Adam Richardson
        307587 by: Nathan Rixham
        307590 by: Tristan
        307591 by: Nathan Rixham
        307592 by: Nisse Engström

Re: tutorial failure
        307584 by: David McGlone
        307586 by: Ashley Sheridan
        307593 by: Colin Guthrie
        307594 by: e-letter
        307596 by: Ashley Sheridan

imagecreate inside an object
        307588 by: Lorenzo Marussi
        307589 by: Ashley Sheridan

Dear Lazy Web: Pseudo Randomisation Strategies on Listing Websites
        307595 by: Colin Guthrie

Administrivia:

To subscribe to the digest, e-mail:
        [email protected]

To unsubscribe from the digest, e-mail:
        [email protected]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
If you're on 5.2 or 5.3, it may have to do with bug #51263.

http://bugs.php.net/51263

Upgrade your php to the latest as fixes the problem.

-bborie

On 08/12/2010 10:08 AM, tedd wrote:

Well, whatever the problem is it is definitely related only to my
system. I tried your code and had the same results
(https://adexfulfillment.com/adex/tests/test.php). I tried different
fonts as well. The fonts I'm using were exported from FontBook on my
Mac. I wonder if that might have something to do with it. Anyway you
could pass along the arial font you're using so I can test that
possibility?

Thanks!
Floyd

Floyd:

It's clearly a font problem.

The arial.ttl font is easily found on the net, such as:

http://www.fontemple.com/key-arial_ttl_download.html

Cheers,

tedd

--
Bborie Park
Programmer
Center for Vectorborne Diseases
UC Davis
530-752-8380
[email protected]

--- End Message ---
--- Begin Message ---
So, I'm have this site where all this code was developed and the logic sits
in different plugins throughout a template. So, html is output and then hits
one of these plugins. Plugins do some processing and then hit a
header(location...) redirect.

So, problem is they developed code with these header redirects and now we
there's too much html being output so we get the buffer errors

Cannot modify header information - headers already sent by (output started
at
/home/carma/templates_c/carma^0^31^811^%%E2^E22^E22E607D%%carma%3Amenu.php:138)

to fix we have to up the buffer ouput in the php to something really high.

So, as far as I know this is not good coding practice and upping the output
buffer is really masking the problem.

Is there another way to work around this like another way to do redirects
that won't cause these buffer probs?

Thanks, T

--- End Message ---
--- Begin Message ---
On Thu, Aug 19, 2010 at 6:01 PM, Tristan <[email protected]> wrote:

> So, I'm have this site where all this code was developed and the logic sits
> in different plugins throughout a template. So, html is output and then
> hits
> one of these plugins. Plugins do some processing and then hit a
> header(location...) redirect.
>
> So, problem is they developed code with these header redirects and now we
> there's too much html being output so we get the buffer errors
>
> Cannot modify header information - headers already sent by (output started
> at
>
> /home/carma/templates_c/carma^0^31^811^%%E2^E22^E22E607D%%carma%3Amenu.php:138)
>
> to fix we have to up the buffer ouput in the php to something really high.
>
> So, as far as I know this is not good coding practice and upping the output
> buffer is really masking the problem.
>
> Is there another way to work around this like another way to do redirects
> that won't cause these buffer probs?
>
> Thanks, T
>

I believe the error is informing you that some content has already been sent
back to the client.  Once any content has been sent back, the headers have
already been set and you can't subsequently call header().

For an easy fix, you should be able to turn on output buffering for the
request and all of the output will be held until the entire page is finished
processing:
http://php.net/manual/en/function.ob-start.php

Alternatively, you can sift through you code looking for any output (even a
single whitespace) that's present before the call to header in  the menu.php
file referenced in your error.

Adam

-- 
Nephtali:  PHP web framework that functions beautifully
http://nephtaliproject.com

--- End Message ---
--- Begin Message ---
Tristan wrote:
So, I'm have this site where all this code was developed and the logic sits
in different plugins throughout a template. So, html is output and then hits
one of these plugins. Plugins do some processing and then hit a
header(location...) redirect.

So, problem is they developed code with these header redirects and now we
there's too much html being output so we get the buffer errors

Cannot modify header information - headers already sent by (output started
at
/home/carma/templates_c/carma^0^31^811^%%E2^E22^E22E607D%%carma%3Amenu.php:138)

to fix we have to up the buffer ouput in the php to something really high.

So, as far as I know this is not good coding practice and upping the output
buffer is really masking the problem.

Is there another way to work around this like another way to do redirects
that won't cause these buffer probs?

Hi Tristan,

Really it's a nudge from your code that it needs refactored - however to answer your question..

- there is no way to do an HTTP redirect once headers are sent
- you can use an html meta refresh, or javascript redirect - if the output is going to be HTML viewed in a browser.

caveat, obviously robots and the like will still see the incorrect output - it's a hack not a fix.

The other approach is to use ob_start() and related functions to capture all the code generated without any output being sent to the browser, this should allow you to send the header down when needed.

Certainly wouldn't just knock output buffering right up high to work around it if I was you.

Best,

Nathan

--- End Message ---
--- Begin Message ---
A rewrite of the entire site would be needed in order to fix. So, I guess
you are saying as best options for workaround are

- use the ob_ functions to work around.
- stick output buffer on or high

so best case scenario using ob_ functions as a cleaner method aside from
rewriting the code?

seems silly btw that you can't output html and just have it redirect
whenever you want it to at any point in the page.

Thanks, T


On Thu, Aug 19, 2010 at 4:22 PM, Nathan Rixham <[email protected]> wrote:

> Tristan wrote:
>
>> So, I'm have this site where all this code was developed and the logic
>> sits
>> in different plugins throughout a template. So, html is output and then
>> hits
>> one of these plugins. Plugins do some processing and then hit a
>> header(location...) redirect.
>>
>> So, problem is they developed code with these header redirects and now we
>> there's too much html being output so we get the buffer errors
>>
>> Cannot modify header information - headers already sent by (output started
>> at
>>
>> /home/carma/templates_c/carma^0^31^811^%%E2^E22^E22E607D%%carma%3Amenu.php:138)
>>
>> to fix we have to up the buffer ouput in the php to something really high.
>>
>> So, as far as I know this is not good coding practice and upping the
>> output
>> buffer is really masking the problem.
>>
>> Is there another way to work around this like another way to do redirects
>> that won't cause these buffer probs?
>>
>
> Hi Tristan,
>
> Really it's a nudge from your code that it needs refactored - however to
> answer your question..
>
> - there is no way to do an HTTP redirect once headers are sent
> - you can use an html meta refresh, or javascript redirect - if the output
> is going to be HTML viewed in a browser.
>
> caveat, obviously robots and the like will still see the incorrect output -
> it's a hack not a fix.
>
> The other approach is to use ob_start() and related functions to capture
> all the code generated without any output being sent to the browser, this
> should allow you to send the header down when needed.
>
> Certainly wouldn't just knock output buffering right up high to work around
> it if I was you.
>
> Best,
>
> Nathan
>

--- End Message ---
--- Begin Message ---
you can if you use a javascript redirect or an html meta refresh ~ish.

not really that silly tbh if you think about an HTTP message is like this:

Headers
...
MessageBody
.....

the redirect is a header, so it get's sent through *before* the body, and the headers tell the client how to process the messagebody (or indeed whether to process it or just do something else).

consider an html page the same as a gif or a zip, it's just a chunk of computer data that gets sent in one, you wouldn't expect to be able to redirect somebody whilst they're halfway through downloading a big zip would you?

but yeah ob_** functions, this way you're catching the entire MessageBody (your html) before sending anything to the client, which then let's you send headers followed by body in your own time.

Best,

nathan

Tristan wrote:
A rewrite of the entire site would be needed in order to fix. So, I guess
you are saying as best options for workaround are

- use the ob_ functions to work around.
- stick output buffer on or high

so best case scenario using ob_ functions as a cleaner method aside from
rewriting the code?

seems silly btw that you can't output html and just have it redirect
whenever you want it to at any point in the page.

Thanks, T


On Thu, Aug 19, 2010 at 4:22 PM, Nathan Rixham <[email protected]> wrote:

Tristan wrote:

So, I'm have this site where all this code was developed and the logic
sits
in different plugins throughout a template. So, html is output and then
hits
one of these plugins. Plugins do some processing and then hit a
header(location...) redirect.

So, problem is they developed code with these header redirects and now we
there's too much html being output so we get the buffer errors

Cannot modify header information - headers already sent by (output started
at

/home/carma/templates_c/carma^0^31^811^%%E2^E22^E22E607D%%carma%3Amenu.php:138)

to fix we have to up the buffer ouput in the php to something really high.

So, as far as I know this is not good coding practice and upping the
output
buffer is really masking the problem.

Is there another way to work around this like another way to do redirects
that won't cause these buffer probs?

Hi Tristan,

Really it's a nudge from your code that it needs refactored - however to
answer your question..

- there is no way to do an HTTP redirect once headers are sent
- you can use an html meta refresh, or javascript redirect - if the output
is going to be HTML viewed in a browser.

caveat, obviously robots and the like will still see the incorrect output -
it's a hack not a fix.

The other approach is to use ob_start() and related functions to capture
all the code generated without any output being sent to the browser, this
should allow you to send the header down when needed.

Certainly wouldn't just knock output buffering right up high to work around
it if I was you.

Best,

Nathan




--- End Message ---
--- Begin Message ---
On Thu, 19 Aug 2010 17:47:01 -0600, Tristan wrote:

> A rewrite of the entire site would be needed in order to fix. So, I guess
> you are saying as best options for workaround are
> 
> - use the ob_ functions to work around.
> - stick output buffer on or high
> 
> so best case scenario using ob_ functions as a cleaner method aside from
> rewriting the code?
> 
> seems silly btw that you can't output html and just have it redirect
> whenever you want it to at any point in the page.

Actually, the HTTP spec. allows most headers to be sent
after the content. The feature just wasn't implemented
by too many HTTP agents (W3's HTML validator and link
checker, and Opera).


/Nisse

--- End Message ---
--- Begin Message ---
On Thu, 2010-08-19 at 22:24 +0100, Ashley Sheridan wrote:
> On Thu, 2010-08-19 at 19:04 +0100, e-letter wrote: 
> > On 19/08/2010, HallMarc Websites <[email protected]> wrote:
> > > I agree with the earlier take on this situation; you need to start at the
> > > beginning and learn the basics regarding the technologies BEFORE you try 
> > > and
> > > manage them. You're trying to drive a car when you don't even know what or
> > > car is and how to operate one so you keep crashing.
> > >
> > > Here are some great sites to check out:
> > > http://wiki.mandriva.com/en/
> > > http://www.pcstats.com/articleview.cfm?articleID=1868
> > > http://www.wikivs.com/wiki/MySQL_vs_PostgreSQL
> > > http://www.w3schools.com/
> > > There are some great books out there as well to help you learn and I
> > > recommend getting the reference guides as well. Since the gist of this
> > > thread seems to be focused on the LAPP set-up and mainly an Apache (?)
> > > configuration issue you might try the forums and mailing lists found there
> > > as well.
> > >
> > No response from apache forum. Looking at the web browser output from
> > the processing of the php file, the partial success of processing the
> > file suggests that the problem is with php; if it was due to apache,
> > html code would be affected as well?
> > 
> 
> No, because Apache doesn't need to process HTML in the same way it
> needs to process PHP. The tag <?php in your code is being sent down to
> your browser as HTML (view the source on the page you're browsing to)
> and interpreted as a tag by your browser, hence what appears to be
> partially processed output.
> 
> It's fairly clear by now that Apache does not know about your PHP
> install (if there even is one)


This is my suspicion also.

> 
> I've just set up and installed PHP and Apache on my Mandriva box since
> I've been at home, and it took all of 5 minutes 

What was the name of the PHP package you installed? I E-Mailed him
offline and had him run the command rpm -q php5 to try and figure out if
php was installed and he replied with this:

<quote>
> No package by this name in the repository; have libphp5_common5
> installed.
</quote>

Well I don't know what the name of the php5 in mandrake, so I can't tell
whether he's actually got php installed at all.


-- 
Blessings,
David M.


--- End Message ---
--- Begin Message ---
On Thu, 2010-08-19 at 18:09 -0400, David McGlone wrote:

> On Thu, 2010-08-19 at 22:24 +0100, Ashley Sheridan wrote:
> > On Thu, 2010-08-19 at 19:04 +0100, e-letter wrote: 
> > > On 19/08/2010, HallMarc Websites <[email protected]> wrote:
> > > > I agree with the earlier take on this situation; you need to start at 
> > > > the
> > > > beginning and learn the basics regarding the technologies BEFORE you 
> > > > try and
> > > > manage them. You're trying to drive a car when you don't even know what 
> > > > or
> > > > car is and how to operate one so you keep crashing.
> > > >
> > > > Here are some great sites to check out:
> > > > http://wiki.mandriva.com/en/
> > > > http://www.pcstats.com/articleview.cfm?articleID=1868
> > > > http://www.wikivs.com/wiki/MySQL_vs_PostgreSQL
> > > > http://www.w3schools.com/
> > > > There are some great books out there as well to help you learn and I
> > > > recommend getting the reference guides as well. Since the gist of this
> > > > thread seems to be focused on the LAPP set-up and mainly an Apache (?)
> > > > configuration issue you might try the forums and mailing lists found 
> > > > there
> > > > as well.
> > > >
> > > No response from apache forum. Looking at the web browser output from
> > > the processing of the php file, the partial success of processing the
> > > file suggests that the problem is with php; if it was due to apache,
> > > html code would be affected as well?
> > > 
> > 
> > No, because Apache doesn't need to process HTML in the same way it
> > needs to process PHP. The tag <?php in your code is being sent down to
> > your browser as HTML (view the source on the page you're browsing to)
> > and interpreted as a tag by your browser, hence what appears to be
> > partially processed output.
> > 
> > It's fairly clear by now that Apache does not know about your PHP
> > install (if there even is one)
> 
> 
> This is my suspicion also.
> 
> > 
> > I've just set up and installed PHP and Apache on my Mandriva box since
> > I've been at home, and it took all of 5 minutes 
> 
> What was the name of the PHP package you installed? I E-Mailed him
> offline and had him run the command rpm -q php5 to try and figure out if
> php was installed and he replied with this:
> 
> <quote>
> > No package by this name in the repository; have libphp5_common5
> > installed.
> </quote>
> 
> Well I don't know what the name of the php5 in mandrake, so I can't tell
> whether he's actually got php installed at all.
> 
> 
> -- 
> Blessings,
> David M.
> 
> 


I used the GUI: K-Menu->Configure your Computer->Install & Remove
Software

Then searched for 'php', and the first package listed was
apache-mod_php, which I installed along with the other php modules that
I normally install (like GD, mcrypt, etc). The package manager sorts out
dependencies very well. I'm not sure if installing over the command line
with rpmi will deal with dependencies like this, and it certainly won't
automatically install apache-mod_php if php is installed, as php doesn't
necessarily *have* to run as a web server module, let alone as an Apache
one specifically.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
'Twas brillig, and Ashley Sheridan at 19/08/10 23:16 did gyre and gimble:
> I used the GUI: K-Menu->Configure your Computer->Install & Remove
> Software
> 
> Then searched for 'php', and the first package listed was
> apache-mod_php, which I installed along with the other php modules that
> I normally install (like GD, mcrypt, etc). The package manager sorts out
> dependencies very well. I'm not sure if installing over the command line
> with rpmi will deal with dependencies like this, and it certainly won't
> automatically install apache-mod_php if php is installed, as php doesn't
> necessarily *have* to run as a web server module, let alone as an Apache
> one specifically.

Just for reference:

1. The Package Manager GUI will indeed sort it all out for you.

2. The Package Manager GUI is just a frontend for urpmi. All the
dependency tracking etc. is in urpmi. It's very much like Yum, but IMO
is easer to use and better at reporting conflicts and other such things.
But to each his own :)

3. Just install task-lamp. Who cares that you get mysql installed? I
doubt the space overhead is a problem and I'm very much presuming that
this is your development PC. No offence intended (we were all new once)
the fact that you are asking the questions you are means that this
simply *cannot* be a production setup!

If you have any doubt and want to be more specific, just install
task-lamp-php. All of these are listed in the Package Manager GUI. Just
pick "Meta Packages" and then look under System->Servers (or just search
for the name: staring the GUI and typing "lamp" into the search box is
really all that's needed).

4. Yes PHP can be installed as cgi, apache module or command line. There
is no such thing as "installing php" - you install which system you
want: command line (php-cli), apache module (apache-mod_php) or cgi
(php-cgi). I work with LAMP stacks on various flavours servers and I
find the Mandriva one to be very, very well thought out, and very
flexibly mainly due to the excellent work of Oden Ericsson.

Col




-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


--- End Message ---
--- Begin Message ---
On 19/08/2010, Ashley Sheridan <[email protected]> wrote:
> No, because Apache doesn't need to process HTML in the same way it needs
> to process PHP. The tag <?php in your code is being sent down to your
> browser as HTML (view the source on the page you're browsing to) and
> interpreted as a tag by your browser, hence what appears to be partially
> processed output.
>
> It's fairly clear by now that Apache does not know about your PHP
> install (if there even is one)
>
> I've just set up and installed PHP and Apache on my Mandriva box since
> I've been at home, and it took all of 5 minutes from within the package
> manager. Trust me, it's far easier to go that route than install the
> packages one-by-one as you seem to be doing as, unless you know exactly
> what packages you need, it's all too easy to miss installing something.
>
Yes that is what I was inspecting; I plan to re-install the entire OS.

--- End Message ---
--- Begin Message ---
On Fri, 2010-08-20 at 10:00 +0100, e-letter wrote:

> On 19/08/2010, Ashley Sheridan <[email protected]> wrote:
> > No, because Apache doesn't need to process HTML in the same way it needs
> > to process PHP. The tag <?php in your code is being sent down to your
> > browser as HTML (view the source on the page you're browsing to) and
> > interpreted as a tag by your browser, hence what appears to be partially
> > processed output.
> >
> > It's fairly clear by now that Apache does not know about your PHP
> > install (if there even is one)
> >
> > I've just set up and installed PHP and Apache on my Mandriva box since
> > I've been at home, and it took all of 5 minutes from within the package
> > manager. Trust me, it's far easier to go that route than install the
> > packages one-by-one as you seem to be doing as, unless you know exactly
> > what packages you need, it's all too easy to miss installing something.
> >
> Yes that is what I was inspecting; I plan to re-install the entire OS.
> 


You don't have to reinstall the entire OS, that's a very Windows
approach to the problem. I played around a bit last night with urpmi and
you should be able to just list the packages you need with urpmq --fuzzy
package_name, and then install the ones listed you think you need. I did
notice that urpmi doesn't install the DB when you install the Apache mod
for that DB, so you might need to install that separately, but other
than that, you should be good to go if you install the Apache php mod.


Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
hello list,

I'm trying to manage a image resouce inside a method, but
unsuccessfully...

In detail, that's some code snippets:

the class and the method:

class.php

class canvas{

    function makeImage($imageWidth = 850){

        $im = imagecreate(110, 20) or die("Cannot Initialize new GD
image stream");
        $background_color = imagecolorallocate($im, 0, 0, 0);
        $text_color = imagecolorallocate($im, 233, 14, 91);
        imagestring($im, 1, 5, 5,  "A Simple Text String", $text_color);
        return $im;
    }

}

... than my test.php file:

header("Content-type: image/png");
include_once("class.php");
$c = new canvas();
imagepng($c->makeImage());

the result in the browser isn't the image itself, but an error that
sounds like: (I traslate the message from italian):
"Image can't be displayed because contains some errors"

but... if I comment out the "header" line, I get this:

‰PNG  ��� IHDR���n������V,š���PLTE���é[an÷���fIDAT•c` `fxÄÀÃ`Ç
ÀçÀä²41ƒ‚€˜Ë–Ý’À...@੤;{á0— œi

...sounds like a png image, isn't it? but It doesn't :-/

The code in the method is very simple, is the same of the php manual
page of "imagecreate" function, and I think the resource is correctly
managed, 'cause if I write this:

$c = new palinsestoCanvas(3);
imagepng(null);

I get: "Warning: imagepng(): supplied argument is not a valid Image
resource" 

.. so I think $c->makeImage()) returns successfully the resource.. but I
still didnt see my image..


Any help is appreciated, thanks

Lorenzo





--- End Message ---
--- Begin Message ---
On Fri, 2010-08-20 at 00:44 +0200, Lorenzo Marussi wrote:

> hello list,
> 
> I'm trying to manage a image resouce inside a method, but
> unsuccessfully...
> 
> In detail, that's some code snippets:
> 
> the class and the method:
> 
> class.php
> 
> class canvas{
> 
>     function makeImage($imageWidth = 850){
> 
>         $im = imagecreate(110, 20) or die("Cannot Initialize new GD
> image stream");
>         $background_color = imagecolorallocate($im, 0, 0, 0);
>         $text_color = imagecolorallocate($im, 233, 14, 91);
>         imagestring($im, 1, 5, 5,  "A Simple Text String", $text_color);
>         return $im;
>     }
> 
> }
> 
> ... than my test.php file:
> 
> header("Content-type: image/png");
> include_once("class.php");
> $c = new canvas();
> imagepng($c->makeImage());
> 
> the result in the browser isn't the image itself, but an error that
> sounds like: (I traslate the message from italian):
> "Image can't be displayed because contains some errors"
> 
> but... if I comment out the "header" line, I get this:
> 
> ‰PNG  ��� IHDR���n������V,š���PLTE���é[an÷���fIDAT•c` `fxÄÀÃ`Ç
> ÀçÀä²41ƒ‚€˜Ë–Ý’À...@੤;{á0— œi
> 
> ...sounds like a png image, isn't it? but It doesn't :-/
> 
> The code in the method is very simple, is the same of the php manual
> page of "imagecreate" function, and I think the resource is correctly
> managed, 'cause if I write this:
> 
> $c = new palinsestoCanvas(3);
> imagepng(null);
> 
> I get: "Warning: imagepng(): supplied argument is not a valid Image
> resource" 
> 
> .. so I think $c->makeImage()) returns successfully the resource.. but I
> still didnt see my image..
> 
> 
> Any help is appreciated, thanks
> 
> Lorenzo
> 
> 
> 
> 


It looks like you might be outputting some extra content to the browser,
such as newlines or other content. Use the second parameter of
imagepng() to write the image to a file and compare the size of that
with the bytes sent to the browser (you should be able to get this from
the browsers properties dialogue)

>From the looks of what you've pasted, the extra content is appearing
right after the image data, so perhaps an exit; call right after
imagepng() and seeing if that solves the problem.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
Hi,

OK, this is really just a sounding board for a couple ideas I'm mulling
over regarding a pseudo-randomisation system for some websites I'm
doing. Any thoughts on the subject greatly appreciated!

Back Story:

We have a system that lists things. The things are broken down by
category, but you can still end up at the leaf of the category with a
couple hundred things to list, which is done via a pagination system
(lets say 50 per page).


Now, the people who own the things pay to have their things on the site.
Lets say there are three levels of option for listing: gold, silver,
bronze. The default order is gold things, silver things then bronze
things. Within each level, the things are listed alphabetically (again
this is just the default).


Now if 100 things in one category have a gold level listing, those in
the second half of the alphabet will be on page two by default. They
don't like this and they question why they are paying for gold at all.

My client would like to present things in a more random way to give all
gold level things a chance to be on the first page of results in a
fairer way than just what they happen to be named.

Right that's the back story. It's more complex than that, but the above
is a nice and simple abstraction.


Problems:

There are numerous problems to randomised listings: you can't actually
truly randomise results otherwise pagination breaks. Server-side
caching/denationalisation is affected as there is no longer "one
listing" but "many random listings". Discussing a link with a friend
over IM or email and saying things like "the third one down looks best"
is obviously broken too, but this is something my client accepts and can
live with. Also, if the intention is to reassure the thing owners that
their listing will appear further up the listings at times, the fact
that a simple refresh will not reorder things for a given session will
make that point harder to get across to less web-educated clients
(that's a nice way of saying it!). Caching proxies and other similar
things after the webserver will also come into play.


So to me there are only really two options:

1. Random-per user (or session): Each user session gets some kind of
randomisation key and a fresh set of random numbers is generated for
each thing. They can then be reliably "randomised" for a given user. The
fact that each user has their own unique randomisation is good, but it
doesn't help things like server side full page caching and thus more
"work" needs to be done to support this approach.

2. Random-bank + user/session assignment: So with this approach we have
a simple table of numbers. First column is an id and is sequential form
1 to <very big number>. This table has lots of columns: say 32. These
columns will store a random number. Once generated, this table acts as
an orderer. It can be joined into our thing lookup query and the results
can be ordered by one of the columns. Which column to use for ordering
is picked by a cookie stored on the users machine. That way the user
will always get the same random result, even if they revisit the site
some time later (users not accepting cookies is not a huge deal, but I
would suggest the "pick a random column" algorithm (used to set the
cookie initially) is actually based on source IP address. That way even
cookieless folks should get a consistent listing unless their change
their IP).



I'm obviously leaning towards the second approach. If I have 32
"pre-randomised" columns, this would get a pretty good end result I
think. If we re-randomise periodically (i.e. once a week or month) then
this can be extended further (or simply more columns can be added).

I think it's the lowest impact but there are sill some concerns:

Server side caching is still problematic. Instead of storing one page
per "result" I now have to store 32. This will lower significantly the
cache hits and perhaps make full result caching somewhat redundant. If
that is the case, then so be it, but load will have to be managed.


So my question for the lazy-web:

Are there any other approaches I've missed? Is there some cunning,
cleverness that eludes me?

Are there any problems with the above approach? Would a caching proxy
ultimately cause problems for some users (i.e. storing a cache for page
1 and page 2 of the same listing but with different randomisations)? And
if so can this be mitigated?

Thanks for reading and any insights you may have!


Col






-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


--- End Message ---

Reply via email to