Welcome! Log In Create A New Profile

Advanced

Re: memcached problems...

JG
September 02, 2009 05:37PM
hello again,

ok, i feed memcached now with this perl script....

--------- code ----------

#!/usr/bin/perl
# Usual suspects
use strict;
use warnings;
# Additional modules needed
use File::Find;
use Cache::Memcached;

### Create Memcache connection
my $cache = new Cache::Memcached {
'servers' => [
'localhost:11211',
],
'compress_threshold' => 10_000,
} or die("Failed to connect to memcache server");

my @content;

### Define root location to search, alter as appropriate
#my $dir = "/home/www/htdocs/";
my $dir="$ARGV[0]" if $ARGV[0];

#$dir.="/$ARGV[0]" if $ARGV[0];
#print "$dir\n";
### Go find those files
find(\&Wanted, $dir);

### Process the found files
foreach my $file(@content){
open (my $source,"<$file");
read $source,my $contents,(stat($file))[7];
$file =~ s/^$dir//;
if ($cache->get($file)){
my $compare = $cache->get($file);
if ($compare ne $contents){
print "Cached file $file is not up to date, updating cache";
$cache->delete($file);
$cache->set($file,$contents);
}
} else {
$cache->set($file,$contents)
}
}

sub Wanted
{
# only operate on image files
/.jpg$/ or /.gif$/ or /.png$/ or return;
push (@content,$File::Find::name);
}

#!/usr/bin/perl
# Usual suspects
use strict;
use warnings;
# Additional modules needed
use File::Find;
use Cache::Memcached;

### Create Memcache connection
my $cache = new Cache::Memcached {
'servers' => [
'localhost:11211',
],
'compress_threshold' => 10_000,
} or die("Failed to connect to memcache server");

my @content;

### Define root location to search, alter as appropriate
#my $dir = "/home/www/htdocs/";
my $dir="$ARGV[0]" if $ARGV[0];

#$dir.="/$ARGV[0]" if $ARGV[0];
#print "$dir\n";
### Go find those files
find(\&Wanted, $dir);

### Process the found files
foreach my $file(@content){
open (my $source,"<$file");
read $source,my $contents,(stat($file))[7];
$file =~ s/^$dir//;
if ($cache->get($file)){
my $compare = $cache->get($file);
if ($compare ne $contents){
print "Cached file $file is not up to date, updating cache";
$cache->delete($file);
$cache->set($file,$contents);
}
} else {
$cache->set($file,$contents)
}
}

sub Wanted
{
# only operate on image files
/.jpg$/ or /.gif$/ or /.png$/ or return;
push (@content,$File::Find::name);
}

----------------------------------

to push jpg gif etc into memcached which works as far is i can see, but nginx still doesnt try to fetch stuff from memcached

heres the part of my config

--------- config --------------


location / {
root /home/www/htdocs/;
index index.html index.htm;

}

location ~* \.(jpg|png|gif)$ {
expires max;
set $memcached_key $uri;
memcached_pass 127.0.0.1:11211;
error_page 404 502 504 @fetch;
}

location ~ \.php$ {
root /home/www/htdocs;
set $memcached_key $uri;
memcached_pass 127.0.0.1:11211;
proxy_intercept_errors on;
error_page 404 502 504 @fetch;

fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/www/htdocs$fastcgi_script_name;
include fastcgi_params;
}

location @fetch {
internal;
expires max;

proxy_pass http://backend;
break;
}

-------- /code --------------

for my understanding nginx should first check if the file is in memcached, and if it gets a 404 there it should went to @fetch which is a 2nd definition looking like this

------- config ------------

upstream backend {
server 127.0.0.1:82;
}

server {
listen 127.0.0.1:82;
server_name localhost;


location / {
root /home/www/htdocs/;
index index.html index.htm;
}

location ~ \.php$ {
root /home/www/htdocs;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/www/htdocs$fastcgi_script_name;
include fastcgi_params;
}
}
-------------------------------


tcpdump on port 11211 doesnt show any activity when jpgs or any other files which are in memcached are called



Edited 1 time(s). Last edit at 09/02/2009 05:39PM by JG.
Subject Author Posted

memcached problems...

Juergen Gotteswinter August 31, 2009 02:05PM

Re: memcached problems...

Igor Sysoev August 31, 2009 03:49PM

Re: memcached problems...

JG August 31, 2009 05:34PM

Re: memcached problems...

Istv August 31, 2009 05:41PM

Re: memcached problems...

JG August 31, 2009 06:15PM

Re: memcached problems...

JG September 02, 2009 05:37PM

Re: memcached problems...

JG September 02, 2009 05:56PM

Re: memcached problems...

JG September 02, 2009 05:58PM

Re: memcached problems...

Igor Sysoev September 03, 2009 05:10AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 224
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready