Re: handler timeout

2018-03-28 Thread Fayland Lam
for long run stuff, people are usually using job queue like gearman,
theschwartz or minion etc.

you can send a ID back to app first, then init another request with
that id to check if it's finished.

Thanks

On Wed, Mar 28, 2018 at 6:31 PM, PANG J. <pa...@uk2.net> wrote:
> what the client I meant is mobile App.
> mobile App gets the result from server via SDK.
> in future we may move the computing task into App itself.
> But currently they are running on server side.
>
> thanks.
>
>
> On 2018/3/28 星期三 PM 6:11, André Warnier (tomcat) wrote:
>>
>> I believe that the timeout which Pang J. is mentioning, may be the
>> browser-side timeout, which is fixed at the browser level at about 5 minutes
>> or so.
>> When a browser sends a request to a server, and it does receive /some/
>> response within the next +-5 minutes, then the browser will drop the
>> connection to the server, and pop up a message saying "sorry, the server
>> appears not to respond.."
>> In other words, it is not a server timeout, it is a client timeout.
>> The only way to avoid this, is to insure that the server sends at least
>> /some/ temporary response to the client (*), regularly, so that this browser
>> timeout does not occur.
>> Unfortunately, that is a bit more complicated to set up, than just some
>> parameter somewhere.
>> But there must be plenty of past discussions of this issue already on the
>> www, and solution guidelines.



-- 
Fayland Lam // http://www.fayland.me/


Re: session module

2010-10-29 Thread Fayland Lam
try a framework. that's much more popular. :)

On Fri, Oct 29, 2010 at 8:20 PM, Perrin Harkins per...@elem.com wrote:
 Both work.  CGI::Session was better maintained for a while but it
 looks like Apache::Session has been updated recently.  Pick the one
 that you find easiest to understand from the documentation.

 - Perrin

 2010/10/29 Jeff Pang jeff_p...@sina.com:
 is Apache::Session or CGI::Session better for mod_perl?

 Thanks.





-- 
Fayland Lam // http://www.fayland.org/


Re: session module

2010-10-29 Thread Fayland Lam
try Dancer. which is very suitable for small application. just one file.

Thanks

On Fri, Oct 29, 2010 at 8:37 PM, Jeff Pang jeff_p...@sina.com wrote:
 于 2010-10-29 20:28, Fayland Lam 写道:

 try a framework. that's much more popular. :)


 I wrote a small application with few scripts.
 A framework like catalyst is too large to use for me.
 Thanks.

 Jeff.





-- 
Fayland Lam // http://www.fayland.org/


Re: global variable

2010-02-03 Thread Fayland Lam

why not use memcached or FastMmap?

Thanks

On 2010-2-3 16:19, m...@normalperson.e4ward.com wrote:

On Wed, Feb 3, 2010 at 4:18 PM,m...@normalperson.e4ward.com  wrote:
   

On Wed, Feb 3, 2010 at 3:20 PM, André Warniera...@ice-sa.com  wrote:

 

But if you give some more details about the platform, the Apache, and what
you are trying to do, someone may be able to suggest an alternative.


   

Something linke java servlet's global variable.
 

sorry for the typo,  something like ...

   



--
Fayland Lam // http://www.fayland.org/



Re: Ways to scale a mod_perl site

2009-09-18 Thread Fayland Lam
This?
http://search.cpan.org/~jkrasnoo/ApacheCookieEncrypted-0.03/Encrypted.pm

Catalyst has a plugin:
http://search.cpan.org/~lbrocard/Catalyst-Plugin-CookiedSession-0.35/lib/Catalyst/Plugin/CookiedSession.pm

Thanks.

On Fri, Sep 18, 2009 at 9:06 PM, Igor Chudov ichu...@gmail.com wrote:
 Michael, you inspired me to reimplement cookies this way. For my site, the
 cookie table is the most frequently updated one (even though I do not grant
 cookies to search engines). I will try to use this kind of implementation.

 Even now, my users like the fact that they can stay signed  on forever, but
 now I can do it at no cost to myself.

 A quick question, is there an existing perl module to do this sort of thing?

 Igor

 On Wed, Sep 16, 2009 at 12:11 PM, Michael Peters mpet...@plusthree.com
 wrote:

 On 09/16/2009 12:13 PM, Brad Van Sickle wrote:

 Can I get you to explain this a little more? I don't see how this could
 be used for truly secure sites because I don't quite understand how
 storing a hash in a plain text cookie would be secure.

 If you need to store per-session data about a client that the client
 shouldn't be able to see, then you just encrypt that data, base-64 encode it
 and then put it into a cookie.

 If you don't care if the user sees that information you just want to make
 sure that they don't change it then add an extra secure hash of that
 information to the cookie itself and then verify it when you receive it.

 I like to use JSON for my cookie data because it's simple and fast, but
 any serializer should work. Something like this:

 use JSON qw(to_json from_json);
 use Digest::MD5 qw(md5_hex);
 use MIME::Base64::URLSafe qw(urlsafe_b64encode urlsafe_b64decode);

 # to generate the cookie
 my %data = ( foo = 1, bar = 2, baz = 'frob' );
 $data{secure} = generate_data_hash(\%data);
 my $cookie = urlsafe_b64encode(to_json(\%data));
 print Cookie: $cookie\n;

 # to process/validate the cookie
 my $new_data = from_json(urlsafe_b64decode($cookie));
 my $new_hash = delete $new_data-{secure};
 if( $new_hash eq generate_data_hash($new_data) ) {
    print Cookie is ok!\n;
 } else {
    print Cookie has been tampered with! Ignore.\n;
 }

 # very simple hash generation function
 sub generate_data_hash {
    my $data = shift;
    my $secret = 'some configured secret';
    return md5_hex($secret . join('|', map { $_ - $data-{$_} } keys
 %$data));
 }

 Doing encryption and encoding on small bits of data (like cookies) in
 memory will almost always be faster than having to hit the database
 (especially if it's on another machine). But the biggest reason is that it
 takes the load off the DB and puts it on the web machines which are much
 easier to scale linearly.

  I know a lot of true app servers (Websphere, etc..) store

 this data in cached memory,

 You could do the same with your session data, or even store it in a shared
 resource like a BDB file. But unless it's available to all of your web
 servers you're stuck with sticky sessions and that's a real killer for
 performance/scalability.

 --
 Michael Peters
 Plus Three, LP





-- 
Fayland Lam // http://www.fayland.org/


share use vars?

2009-07-16 Thread Fayland Lam
see we are using Catalyst and it run under mod_perl2. we're planning to 
use Geo::IP in our Controller.

I'm wondering which code is better as following.

1)
use vars qw/$geo_ip/;
sub ip_to_location {
   my ( $ip ) = @_;
  
   $geo_ip ||= Geo::IP-open(/usr/local/share/GeoIP/GeoLiteCity.dat, 
GEOIP_STANDARD);

   my $record = $geo_ip-record_by_addr($ip);
   return unless $record;
   return ( $record-country_code, $record-city, 
$record-country_name, $record-region_name );

}

2)
use vars qw/$geo_ip/;
$geo_ip = Geo::IP-open(/usr/local/share/GeoIP/GeoLiteCity.dat, 
GEOIP_STANDARD);

sub ip_to_location {
   my ( $ip ) = @_;
  
   my $record = $geo_ip-record_by_addr($ip);

   return unless $record;
   return ( $record-country_code, $record-city, 
$record-country_name, $record-region_name );

}

I'm wondering in which way the $geo_ip is sharable through the threads.
we are using server/mpm/prefork

Thanks.

--
Fayland Lam // http://www.fayland.org/
Foorum based on Catalyst // http://www.foorumbbs.com/



Re: org stuff

2006-05-13 Thread Fayland Lam

David Dick wrote:

Fayland Lam wrote:
my $dbh = DBI-connect(DBI:mysql:zorpia:z3-1.zorpia.com, 
'zorpia', 'fok8fok2', 


G'day Fayland,

Please note that including credentials in a post to a public mailing 
list is probably not a good idea.  If you are still using these 
credentials it would be a good idea to change them immediately.


I know. I just send it to newsgroup by mistake, I want to send it to my 
boss. just an accident.


We have changed this password already, thanks.




Uru
-David Dick





org stuff

2006-05-12 Thread Fayland Lam

let me explain in Chinese, :)

in the org.conf

Perl
use lib qw(/var/org);
/Perl

PerlModule Zorpia::RewriteOrg
PerlTransHandler Zorpia::RewriteOrg


The PerlTransHandler 能把 url 转变为另一个 url, 比如我们就是将类如
http://org.zorpia.com/0/1584/10141597.0f8688.jpg
这样的 url 转变为
http://org.zorpia.com/org62/0/1584/10141597.0f8688.jpg

这里因为要访问数据库,所以用 mod_rewrite 是不行的。只能依靠 modperl
而 modperl 只是跟 Apache 打交道,不能将这个地址访问到另外服务器上的文 
件。(也就是访问不到 org62 这个服务器)。当然它可以发送一个 header: 
Location 转到 org62, 但是这样子地址栏是会变到 org62 。


怎么样才能在这个 apache 里访问 org62 服务器上的东西。那只能依靠 mod_proxy

RewriteEngine On
RewriteLog /var/log/httpd/rewrite_log
RewriteLogLevel 3
RewriteRule ^/org(\d+)/(.*) http://org$1.zorpia.com/$2 [proxy,last]

这样我们就可以将 http://org.zorpia.com/org62/0/1584/10141597.0f8688.jpg 
用 proxy 访问 http://org62.zorpia.com/0/1584/10141597.0f8688.jpg

对于用户来说这是不可见的。

That's ALL.

而 PerlTransHandler Zorpia::RewriteOrg 也很简单。

if ($r-uri =~ m|/(\d+)/(\d+)/([\w\.]+)\.jpg$|) {
my $org = get_org_from_photo_id($1, $2);
$r-uri(/org$org/$1/$2/$3\.jpg);
}

将访问的 url 转一下。老板你看看就明白了。

另外我想说的是,目前我用的是 Apache2 和 modperl2, 因为 alpha.zorpia 这台 
机子用的是这两个版本的。如果要转到 apache 1.3 和 modperl1 也是很容易的。
还有就是 log 问题。如果到最后发布的时候不需要 log(这样能稍微节省一点点 
资源),就把 conf 里的 RewriteLog 和 RewriteLogLevel 注释掉。还有 
RewriteOrg.pm 与 Apache2::Log 相关的内容。
另外还有个是 RewriteOrg.pm 目前是直接用 DBI 连接的。如果有可能我们可以迁 
移到 Apache::DBI.


Thanks. 如果有问题就问我。:) 我拿着工资的。呵呵。
VirtualHost *:80
#   DocumentRoot /var/www/Zorpia

#SetEnv PERL5LIB /var/www/fayland/Zorpia/lib
#PerlSwitches -I/var/www/Zorpia/lib
Perl
use lib qw(/var/org);
/Perl

PerlModule Zorpia::RewriteOrg
PerlTransHandler Zorpia::RewriteOrg

RewriteEngine On
RewriteLog /var/log/httpd/rewrite_log
RewriteLogLevel 3
RewriteRule ^/org(\d+)/(.*) http://org$1.zorpia.com/$2 [proxy,last]

ErrorLog /var/log/httpd/org.log
ServerName org.zorpia.com
/VirtualHost
package Zorpia::RewriteOrg;
  
#use Apache::Constants qw(DECLINED);
use Apache2::RequestRec ();
use Apache2::Const -compile = qw(DECLINED);
use Apache2::Log;

use strict;
use Zorpia::DB();

sub handler {
my $r = shift;

# convert something like http://org.zorpia.com/0/1584/10141597.0f8688.jpg
# to http://org.zorpia.com/org62/0/1584/10141597.0f8688.jpg
# and we'll use mod_rewrite/mod_proxy to 
http://org62.zorpia.com/0/1584/10141597.0f8688.jpg

$r-log_error($r-uri);

if ($r-uri =~ m|/(\d+)/(\d+)/([\w\.]+)\.jpg$|) {
my $org = get_org_from_photo_id($1, $2);
$r-uri(/org$org/$1/$2/$3\.jpg);
}

#return DECLINED;
return Apache2::Const::DECLINED;
}

# borrow from photoaction.cgi sub original
sub get_org_from_photo_id {
my ($directory_1, $directory_2) = @_;

my $dbh = DBI-connect(DBI:mysql:zorpia:z3-1.zorpia.com, 'zorpia', 
'fok8fok2', 
   { PrintError = 1,
 RaiseError = 1,
 AutoCommit = 1, }) or die $DBI::errstr;

my $sql_statement = SQL_STATEMENT;
SELECT server, base_directory FROM directory_location 
WHERE directory_1 = ? AND directory_2 = ? AND type='org'
SQL_STATEMENT
my $sth = $dbh-prepare($sql_statement);
$sth-execute($directory_1, $directory_2);
my ($server, $base_directory) = $sth-fetchrow_array;
$sth-finish;

my $index_1 = $1 if ($server =~ m/(\d+)$/);
my $index_2 = $1 if ($base_directory =~ m/(\d+)$/);

return $index_1$index_2;
}

1;

Re: org stuff

2006-05-12 Thread Fayland Lam

Fayland Lam wrote:

let me explain in Chinese, :)

in the org.conf

Perl
use lib qw(/var/org);
/Perl

PerlModule Zorpia::RewriteOrg
PerlTransHandler Zorpia::RewriteOrg


The PerlTransHandler 能把 url 转变为另一个 url, 比如我们就是将类如
http://org.zorpia.com/0/1584/10141597.0f8688.jpg
这样的 url 转变为
http://org.zorpia.com/org62/0/1584/10141597.0f8688.jpg

这里因为要访问数据库,所以用 mod_rewrite 是不行的。只能依靠 modperl
而 modperl 只是跟 Apache 打交道,不能将这个地址访问到另外服务器上的文 
件。(也就是访问不到 org62 这个服务器)。当然它可以发送一个 header: 
Location 转到 org62, 但是这样子地址栏是会变到 org62 。


怎么样才能在这个 apache 里访问 org62 服务器上的东西。那只能依靠 mod_proxy

RewriteEngine On
RewriteLog /var/log/httpd/rewrite_log
RewriteLogLevel 3
RewriteRule ^/org(\d+)/(.*) http://org$1.zorpia.com/$2 [proxy,last]

这样我们就可以将 http://org.zorpia.com/org62/0/1584/10141597.0f8688.jpg 
用 proxy 访问 http://org62.zorpia.com/0/1584/10141597.0f8688.jpg

对于用户来说这是不可见的。

That's ALL.

而 PerlTransHandler Zorpia::RewriteOrg 也很简单。

if ($r-uri =~ m|/(\d+)/(\d+)/([\w\.]+)\.jpg$|) {
my $org = get_org_from_photo_id($1, $2);
$r-uri(/org$org/$1/$2/$3\.jpg);
}

将访问的 url 转一下。老板你看看就明白了。

另外我想说的是,目前我用的是 Apache2 和 modperl2, 因为 alpha.zorpia 这台 
机子用的是这两个版本的。如果要转到 apache 1.3 和 modperl1 也是很容易的。
还有就是 log 问题。如果到最后发布的时候不需要 log(这样能稍微节省一点点 
资源),就把 conf 里的 RewriteLog 和 RewriteLogLevel 注释掉。还有 
RewriteOrg.pm 与 Apache2::Log 相关的内容。
另外还有个是 RewriteOrg.pm 目前是直接用 DBI 连接的。如果有可能我们可以迁 
移到 Apache::DBI.


Thanks. 如果有问题就问我。:) 我拿着工资的。呵呵。




VirtualHost *:80
#   DocumentRoot /var/www/Zorpia

#SetEnv PERL5LIB /var/www/fayland/Zorpia/lib
#PerlSwitches -I/var/www/Zorpia/lib
Perl
use lib qw(/var/org);
/Perl

PerlModule Zorpia::RewriteOrg
PerlTransHandler Zorpia::RewriteOrg

RewriteEngine On
RewriteLog /var/log/httpd/rewrite_log
RewriteLogLevel 3
RewriteRule ^/org(\d+)/(.*) http://org$1.zorpia.com/$2 [proxy,last]

ErrorLog /var/log/httpd/org.log
ServerName org.zorpia.com
/VirtualHost




package Zorpia::RewriteOrg;
  
#use Apache::Constants qw(DECLINED);

use Apache2::RequestRec ();
use Apache2::Const -compile = qw(DECLINED);
use Apache2::Log;

use strict;
use Zorpia::DB();

sub handler {
my $r = shift;

# convert something like http://org.zorpia.com/0/1584/10141597.0f8688.jpg
# to http://org.zorpia.com/org62/0/1584/10141597.0f8688.jpg
# and we'll use mod_rewrite/mod_proxy to 
http://org62.zorpia.com/0/1584/10141597.0f8688.jpg

$r-log_error($r-uri);

if ($r-uri =~ m|/(\d+)/(\d+)/([\w\.]+)\.jpg$|) {

my $org = get_org_from_photo_id($1, $2);
$r-uri(/org$org/$1/$2/$3\.jpg);
}

#return DECLINED;
return Apache2::Const::DECLINED;
}

# borrow from photoaction.cgi sub original
sub get_org_from_photo_id {
my ($directory_1, $directory_2) = @_;

my $dbh = DBI-connect(DBI:mysql:zorpia:z3-1.zorpia.com, 'zorpia', 'fok8fok2', 
   { PrintError = 1,

 RaiseError = 1,
 AutoCommit = 1, }) or die $DBI::errstr;

my $sql_statement = SQL_STATEMENT;
SELECT server, base_directory FROM directory_location 
WHERE directory_1 = ? AND directory_2 = ? AND type='org'

SQL_STATEMENT
my $sth = $dbh-prepare($sql_statement);
$sth-execute($directory_1, $directory_2);
my ($server, $base_directory) = $sth-fetchrow_array;
$sth-finish;

my $index_1 = $1 if ($server =~ m/(\d+)$/);
my $index_2 = $1 if ($base_directory =~ m/(\d+)$/);

return $index_1$index_2;
}

1;


sorry, wrong post



can PerlTransHandler deal with this?

2006-05-11 Thread Fayland Lam

let me describe my situation. we have something like

http://o1.example.com/1.jpg
http://o2.example.com/2.gif
http://o3.example.com/4.jpg

and we have a table like:

img   | site
1.jpg | o1
2.gif | o2


and now we want the people visit this by
http://o.example.com/1.jpg
http://o.example.com/2.gif
...

yes, o1,o2,o3 are different servers. I'd like to config the 
o.example.com  like PerlTransHandler +MyApache2::RewriteO
but it seems that PerlTransHandler can only rewrite the url of 
http://o.example.com/1.jpg to http://o.example.com/something

is there a way to http://o1.example.com/1.jpg?
I think i'm using the wrong handler, but is there any handler can handle 
this problem?

or any hint? thanks for any tips.



Re: can PerlTransHandler deal with this?

2006-05-11 Thread Fayland Lam

Frank Maas wrote:

I think i'm using the wrong handler, but is there any handler can handle
this problem?


As far as I can remember mod_rewrite kicks in after a PerlTransHandler. This 
should enable you to use a TransHandler to rewrite the URI based on the 
database contents, eg:

http://o.example.com/2.gif - http:/o.example.com/REDIR/o2.example.com/2.gif

(be sure to return DECLINED) and then have mod_rewrite/mod_proxy proxy this for 
you:

RewriteRule http://o.example.com/REDIR/(.*) http://$1 [proxy,last]

the 'REDIR' tag can be anything suitable for matching. The end user should not 
notice this.

Not tested, but think it should work

Regards,
Frank




Thanks, I'll have a try.



Re: how to configure the mod_perl to show a jpeg file.

2006-01-16 Thread Fayland Lam

黄叶 wrote:
but, if i had a project, i want put the all thing a directory. Can i do 
like that? if I don't use the ModPerl::Registry or edit the 
ModPerl::Registry, that is correct? or there are the other way? thanks.


it works on my side:

# for ModPerl::Registry scripts
Alias /perl/ C:/Apache2/perl/

# see http://localhost/printenv
Location /perl
  SetHandler perl-script
  PerlResponseHandler ModPerl::Registry
  Options +ExecCGI
  PerlOptions +ParseHeaders
  PerlOptions +SetupEnv
/Location
Location /perl/img
  SetHandler default-handler
/Location

I can visit http://localhost/perl/img/1.jpg