Posted by ludo1960 on May 22, 2011 at 9:30am
Hi there,
Just upgraded a site to pressflow from drupal 6 and the performance boost is well worth the effort.
Using the zeropoint theme, it has a rotating banner in the header (rotate.php) However it doesn't work anymore. Using firebug I see:
background: url("/sites/all/themes/zeropoint/_custom/headerimg/rotate.php") no-repeat scroll 100% 100% So it is finding the file, but it wont run. Tried changing the permission to 777 and flushing the cache but it still refuses to run, got me stumped anyone any ideas?
Thanks...
Comments
Uw, php inside of CSS,
Uw, php inside of CSS, mhhh...
What happens if you open http://yoursite.com/sites/all/themes/zeropoint/_custom/headerimg/rotate.php ?
Hmmm
Very strange, I get a 403 Forbidden when I go to http://yoursite.com/sites/all/themes/zeropoint/_custom/headerimg/rotate.php
you have the varnish still in
you have the varnish still in front of the Apache?
What happens when you access the file directly to the apache?
Not sure
Not sure what you mean, this is on a hosted system using Aegir I don't have access to apache configs.
Take a look under the hood
Take a look under the hood. That rotate.php file is being called as a background image in CSS. Is that default in Zeropoint? See what's going on there, and make sure you're actually calling the code. You may want to change the code to something else. The Danland theme has an easy one you can take a look at (you don't need the whole theme). You can also look at Rotor module, if you don't want to deal with jquery yourself.
But jquery may be the problem as well. Too many moving parts to know exactly.
"Take a look under the hood.
"Take a look under the hood. That rotate.php file is being called as a background image in CSS. Is that default in Zeropoint?"
Yes it is the default of the theme. Where about in the danland theme should I look for the example you mention?
I'm stumped!
In the Danland theme (btw,
In the Danland theme (btw, which Drupal version?), look in page.tpl.php. There's a simple jquery code there using jquery slideshow. The images are under the .slideshow div. Then in the template.php file it calls jquery.cycle.all.js in the scripts directory.
htaccess
Is There an htaccess in the parent directory of this php file causing this 403?
No htaccess files in the
No htaccess files in the parent directory, not sure what else to try.
Received this from the hosting company:
This is expected. Our configuration doesn't support
any php files in themes.
By the way, it should never be used. Any image rotation
etc should be handled via javascript, so it is a bad practice
in the theme design, as images should never be served
via php (unless for imagecache module).
That makes sense. I'd never
That makes sense. I'd never seen that before (php in css). Use the Danland example instead. Copy the code in the page.tpl (change the images in .slideshow to yours), the jquery cycle script and the template.php call (change it to wherever you place the script). That may be your best bet, because you won't get that php file to work (nor should you).
I had a look at Danland, I
I had a look at Danland, I see the bit in template.php and the script but I can't see anything in page.tpl
There should be a div with
There should be a div with the class ".slideshow". I definitely see it in the D7 version, and I remember it in the D6 version. Check to see if there is a page-front.tpl.php file -- it may only be there. And look for jQuery(document).ready(function($) in that file. I have an older version in D6, so I may have added some of that from somewhere else.
Thanks for the info, yep in
Thanks for the info, yep in page_front.tpl
<script type="text/javascript">jQuery(document).ready(function($) {
$('.slideshow').cycle({
fx: 'fade' , timeout: 8000, delay: 2000});
});</script>
Thanks for the info, yep in
Thanks for the info, yep in page_front.tpl
<script type="text/javascript">jQuery(document).ready(function($) {
$('.slideshow').cycle({
fx: 'fade' , timeout: 8000, delay: 2000});
});</script>
Views Slideshow
Why aren't you using Views Slideshow for your image rotation?
If you need text on top of the images, watch the video podcast about it at mustardseedmedia.com
MIKO, Creative Technical Support and Developer
Miko's Support and Design Services, Seattle
http://mikosweb.com
Thanks for input, the only
Thanks for input, the only reason I used the theme to add the rotate.php is I didn't know that was a no no! And it's a built in feature of the theme. I have opened an issue on the zeropoint page. Seems like it's a opened a can of worms!
That method is also less than
That method is also less than ideal from a performance standpoint. The browser can never cache the images because they're all called rotate.php. So every new page load means downloading a full image again, even if that same image was loaded on another page.
If this is like another theme I've seen, it isn't a rotating slideshow. Each page load the client browser calls rotate.php which picks a random image from a list and returns it for use in the header image. The better way to do that is to define preprocess_page in template.php and include code to pick a random image, assigns the url of the image to a variable, and then that variable is placed in page.tpl.php in an img tag. Sorry, I don't have any code ready made.
One problem there is with
One problem there is with page caching. The front page (and every other page) would have the same image for anonymous visitors until the cache is refreshed.
I've never used the Zeropoint theme, but just took a look at the rotate.php file. Yeah that is actually not a good way to do it. Instead it would probably be better to select the file, then do a 302 redirect to the actual image. That would keep caching enabled on the actual image files.
HollyIT - Grab the Netbeans Drupal Development Tool at GitHub.
True. My way is not Varnish
True. My way is not Varnish friendly. Doing a directory scan for each page is also not efficient. And a 302 is a nice simple fix but still uses a php file and dir scan and additional request.
What would be the most efficient method without using a separate php file? Enter a list of image files in the ui, pass that list in CDATA on every page and let client side java pick one randomly?
Without the separate file,
Without the separate file, javascript is about the only way to go. Generate a list of the images and store them in an array, then add them as a setting via drupal_add_js, then have the javascript pick a random file from that setting (Drupal.settings.randomimages, or whatever you call it).
Of course there is a downside to this also. You'll want to have a default image in there for browsers that don't support Javascript, or people who have it disabled. That means for the people with Javascript, you would have that image request plus the random image.
If you went the PHP route, there's not need to do a directory scan on every page request. If you aren't going to be updating images more than once every few months, then just hard code them in. If you are going more frequent, then create a cron script that reads that directory every hour or so and either automatically generates a new rotate.php script or stores them in a text file that rotate.php runs.
If you're running APC, then the php route really isn't that bad. I just did a quick script doing the array method and was able to pull out over 2,000 requests per second on a small Linode 512 VPS, which is also running 3 sites, client monitoring and an email server:
Concurrency Level: 100Time taken for tests: 0.420 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 244000 bytes
HTML transferred: 32000 bytes
Requests per second: 2379.31 [#/sec] (mean)
Time per request: 42.029 [ms] (mean)
Time per request: 0.420 [ms] (mean, across all concurrent requests)
Transfer rate: 566.94 [Kbytes/sec] received
Like I said, this was a quick sample script. An actual script would probably be quicker. I was generating an array of 50 items and to get something in there, I just did an MD5 of microtime, which eats up a lot of extra processing power.
HollyIT - Grab the Netbeans Drupal Development Tool at GitHub.
Well
I've fixed a similar thing using Marinelli in a client site. In my case it was as easy as enabling that location explicitly on the nginx config. Something like.
## Use the banner rotation script.location = /sites/all/themes/marinelli/img/banners/rotate.php {
fastcgi_pass phpcgi; # depends on upstream directive
}
As a good security practice you should constrain which locations can run PHP scripts. In drupal there aren't that many. Albeit some modules use ad hoc scripts, in that situation enable each script on a case by case basis.
I strongly suspect that your web server config as the source of the problem.
Yes, but his host isn't cool
Yes, but his host isn't cool with that, and rotate.php is hackish to begin with.
So no easy fix then!!!
So no easy fix then!!! :)
Tried that rotor banner thingy and the thought crossed my mind, is it possible to call the rotor view with javascript and no PHP?