Re: Saving param after new recall of a cgi script

2009-12-01 Thread Rene Schickbauer

Marek wrote:

Hi!


How do I save the parameters from the first input? I tried everything,
but there is nothing kept in my array. Do I have to save these
parameters into an external file?


You could also use Storable & Base64 to encode your data structure into 
a Base64 string. Put this string into a hidden text field. When the 
second form is submitted, you can decode your original data structure 
from that hidden field.


That way, you don't have to store ANYTHING on your server until the user 
hits the final SUBMIT.


Something like this could do the trick:


I originally wrote it to store perl data structures into a database text 
field, should work in a hidden HTML form, too. Something like this:





LG
Rene

--
To unsubscribe, e-mail: beginners-cgi-unsubscr...@perl.org
For additional commands, e-mail: beginners-cgi-h...@perl.org
http://learn.perl.org/




Re: Loading results (via ajax) from a CGI

2009-12-01 Thread Rene Schickbauer

bu...@alejandro.ceballos.info wrote:
I have a CGI (made with cgi.pm) that receive a parameters, check against 
a DB and returns a text with "not found" or "OK found" message. Pretty 
simple.


In other site, i have an ajax routine that sends the parameters (via 
get) and is expected to capture the resulting page, but is not working. 
If I try with a static page, there is not problem, only when calling 
that CGI.


The may be a problem with your headers. What i mean is, is the browser 
(wrongly) caching the page you request?


Try setting the correct headers. Also, you might add an ever-changing 
dummy value to your request to trick the browser into thinking this is a 
new, non-cached page.


You have
var myurl = 'http://server/script.cgi?value='+int_value;

change to:

var myurl = 'http://server/script.cgi?value='+int_value + '&dummyvalue=' 
+ now.getTime();


LG
Rene

--
To unsubscribe, e-mail: beginners-cgi-unsubscr...@perl.org
For additional commands, e-mail: beginners-cgi-h...@perl.org
http://learn.perl.org/




cgi and perl database interaction

2009-12-01 Thread Paweł Prędki

Hello,
I have a website that uses a php engine for news generation and, 
basically, most of the other pages. It uses a MySQL database to store 
the majority of the page contents (i.e. news).


However, I've written before that I've started using simple CGI scripts 
in Perl to make some activities automatic (i.e. statistics updates, 
standings updates - it's a sports-related website :) ).


At first, I used the Storable module and kept all the data in flat files 
but it generally is not the best solution so I moved to DBI.


Now, the thing is that the PHP scripts also connect to the database and, 
presumably, uphold the connection over the duration of the session so as 
not to disconnect and reconnect continually when the user browses the 
website.


My question is - is it possible to do the same thing with those CGI 
scripts? At the moment, each script 'requires' a module where a function 
is defined which returns a database handle upon connecting to the 
database. This is not an efficient solution and I would like to change 
that. There is no mod_perl running on the server but maybe there is a 
way to keep the connection via some Apache mechanisms. I'm not 
experienced with the server operation that much so forgive me if what I 
wrote is hogwash ;)

Cheers,
Pawl

--
To unsubscribe, e-mail: beginners-cgi-unsubscr...@perl.org
For additional commands, e-mail: beginners-cgi-h...@perl.org
http://learn.perl.org/




Re: cgi and php database interaction

2009-12-01 Thread Paweł Prędki

I changed the topic of the e-mail. Sorry for the confusion.

Paweł Prędki pisze:

Hello,
I have a website that uses a php engine for news generation and, 
basically, most of the other pages. It uses a MySQL database to store 
the majority of the page contents (i.e. news).


However, I've written before that I've started using simple CGI scripts 
in Perl to make some activities automatic (i.e. statistics updates, 
standings updates - it's a sports-related website :) ).


At first, I used the Storable module and kept all the data in flat files 
but it generally is not the best solution so I moved to DBI.


Now, the thing is that the PHP scripts also connect to the database and, 
presumably, uphold the connection over the duration of the session so as 
not to disconnect and reconnect continually when the user browses the 
website.


My question is - is it possible to do the same thing with those CGI 
scripts? At the moment, each script 'requires' a module where a function 
is defined which returns a database handle upon connecting to the 
database. This is not an efficient solution and I would like to change 
that. There is no mod_perl running on the server but maybe there is a 
way to keep the connection via some Apache mechanisms. I'm not 
experienced with the server operation that much so forgive me if what I 
wrote is hogwash ;)

Cheers,
Pawl



--
To unsubscribe, e-mail: beginners-cgi-unsubscr...@perl.org
For additional commands, e-mail: beginners-cgi-h...@perl.org
http://learn.perl.org/




Re: cgi and perl database interaction

2009-12-01 Thread Rene Schickbauer

Hi!

Now, the thing is that the PHP scripts also connect to the database and, 
presumably, uphold the connection over the duration of the session so as 
not to disconnect and reconnect continually when the user browses the 
website.


My question is - is it possible to do the same thing with those CGI 
scripts?


CGI scripts are basically scripts executed at the commandline with a few 
parameters and environment variables set (each call normally starts a new 
instance).


You could look into the various web frameworks if and how they solved the 
problem. If you can't install anything on the server besides CGI scripts, 
you're probably out of luck, though.


If you CAN install additional software on the server, mod_perl could be the way 
to go. Or run your own small perl-based server for those pages on another port, 
HTTP::Server::Simple::CGI (or my Maplat-Framework) might fit your profile - you 
may even run them as backend only on localhost and use a PHP script as simple 
proxy 8-)


It really depends on what you're planing in the long run.

LG
Rene

--
#!/usr/bin/perl #99BoB (C)2004 cavac:prg count drink vessel place act1 act2
@a...@argv;$c=$a[0]||99;$b=" ".($a[2]||"bottles")." of ".($a[1]||"beer");$w=" ".
($a[3]||"on the wall").",";do{print"$c$b$w\n$c$b,\n".($a[4]||"take one down").
", ".($a[5]||"pass it around").",\n".--$c."$b$w\n\n";}while($c);print"END!\n";

--
To unsubscribe, e-mail: beginners-cgi-unsubscr...@perl.org
For additional commands, e-mail: beginners-cgi-h...@perl.org
http://learn.perl.org/




Re: cgi and perl database interaction

2009-12-01 Thread Paweł Prędki

Hi!
Thanks for the quick reply. I know it would be much simpler if I just
installed mod_perl and some kind of a framework (I've started learning
Mason and I think I would be able to do what I want using this solution
) and rewrote the whole webpage but that's too much work and it's really
not necessary :) The site is not big, we don't have much traffic so such
inefficiencies don't cost us much. I just wanted to know if there was a
straightforward solution to this problem and I figured there could be
problems with such injection of Perl into a php-dominated application :)

I will look into the HTTP::Server::Simple::CGI and your framework but
I'm not sure I'm knowledgeable enough to deal with that :) I mean I
don't really get the idea of a phps being only proxies. At the moment a
sample php file where I include my own cgi script looks like this:



However, there are also a lot of files where there is much more php code
and no perl code as well as small panels written in pure perl :) How
would the distinction of what serves which pages work?

I know that, in the long run, such distinction and such way of doing
things makes little sense but, like I said, I don't want to restructure
the whole site (I want to keep the php engine which is rather useful and
user-friendly) but I want to use my CGI scripts in an efficient way. To
be honest, the most efficient way would be to rewrite those scripts in
php which shouldn't be too big of a problem but I'm really interested in
Perl right now and that's where I stand :)


Rene Schickbauer pisze:

Hi!

Now, the thing is that the PHP scripts also connect to the database 
and, presumably, uphold the connection over the duration of the 
session so as not to disconnect and reconnect continually when the 
user browses the website.


My question is - is it possible to do the same thing with those CGI 
scripts?


CGI scripts are basically scripts executed at the commandline with a few 
parameters and environment variables set (each call normally starts a 
new instance).


You could look into the various web frameworks if and how they solved 
the problem. If you can't install anything on the server besides CGI 
scripts, you're probably out of luck, though.


If you CAN install additional software on the server, mod_perl could be 
the way to go. Or run your own small perl-based server for those pages 
on another port, HTTP::Server::Simple::CGI (or my Maplat-Framework) 
might fit your profile - you may even run them as backend only on 
localhost and use a PHP script as simple proxy 8-)


It really depends on what you're planing in the long run.

LG
Rene




--
To unsubscribe, e-mail: beginners-cgi-unsubscr...@perl.org
For additional commands, e-mail: beginners-cgi-h...@perl.org
http://learn.perl.org/




Re: cgi and perl database interaction

2009-12-01 Thread Greg Jetter
On Tuesday 01 December 2009 2:52:38 pm Paweł Prędki wrote:
> Hello,
> I have a website that uses a php engine for news generation and,
> basically, most of the other pages. It uses a MySQL database to store
> the majority of the page contents (i.e. news).
>
> However, I've written before that I've started using simple CGI scripts
> in Perl to make some activities automatic (i.e. statistics updates,
> standings updates - it's a sports-related website :) ).
>
> At first, I used the Storable module and kept all the data in flat files
> but it generally is not the best solution so I moved to DBI.
>
> Now, the thing is that the PHP scripts also connect to the database and,
> presumably, uphold the connection over the duration of the session so as
> not to disconnect and reconnect continually when the user browses the
> website.
>
> My question is - is it possible to do the same thing with those CGI
> scripts? At the moment, each script 'requires' a module where a function
> is defined which returns a database handle upon connecting to the
> database. This is not an efficient solution and I would like to change
> that. There is no mod_perl running on the server but maybe there is a
> way to keep the connection via some Apache mechanisms. I'm not
> experienced with the server operation that much so forgive me if what I
> wrote is hogwash ;)
> Cheers,
> Pawl

There  is absolutely no  reason to keep a  connection to the database  active 
once the query has finished and the results are fetched and processed , doing 
so  only ties up system resources and memory. The default  for  Mysql in a  
un- altered server  install is 50 concurrent connections.  A web site can very 
easily surpass this  if the  connections are  kept alive. The  behavior of the  
DBI module returning a handle that you interact  with  is the most efficient 
use 
of  resources .   And I'm pretty sure if you research it you will find that PHP 
does the same thing as PHP is modled after Perl on many levels. Once the 
object is created it persist for the duration of the  script  or until it is   
destroyed with a call to disconnect. Or you risk  getting "unable to connect , 
too many  connections" from your MySql server. and if you  have not  
programmed  to handle the error , you  will get  silent failure with  the  
page  just hanging up  never completing a read or write.  

good luck

Greg



--
To unsubscribe, e-mail: beginners-cgi-unsubscr...@perl.org
For additional commands, e-mail: beginners-cgi-h...@perl.org
http://learn.perl.org/