# CGI Session Synchronization

**URL:** <https://www.ruby-forum.com/t/cgi-session-synchronization/146000>\
**Category:** Ruby\
**Created:** [August 16, 2008, 12:12am UTC](https://www.ruby-forum.com/t/cgi-session-synchronization/146000 "2008-08-16T00:12:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lynchnco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c77e96/32.png) [@lynchnco](https://www.ruby-forum.com/u/lynchnco)\
**Post date:** [August 16, 2008, 12:12am UTC](https://www.ruby-forum.com/t/cgi-session-synchronization/146000/1 "2008-08-16T00:12:24Z")

</div>

I finally tracked down a bug that’s been bothering me, and I’m at a  
complete loss for how to fix it. If you have wisdom, please share. =)

I’m opening a CGI Session using Session.new and storing in $SESSION.

Unfortunately, my webpage has multiple windows open at a time, each of  
which runs in it’s own ruby VM, and accesses it’s own $SESSION.

Is there a way I can synchronize my $SESSION variable?  
eg. Wait for the current Session to be closed before opening it again?

eg.  
In one window I’m running \<Temp.rb\>  
which does:

$SESSION = CGI::Session.new  
#bla #bla #bla  
$SESSION.close

and in another window I’m running \<Temp2.rb\>  
which does :

$SESSION = CGI::Session.new \<— I want this line to stall until  
Temp.rb is done  
#bla bla bla  
$SESSION.close

Thank you very very much for your help.  
-Patrick

---

<div class="post-metadata">

**Author:** ![lynchnco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c77e96/32.png) [@lynchnco](https://www.ruby-forum.com/u/lynchnco)\
**Post date:** [August 16, 2008, 8:44am UTC](https://www.ruby-forum.com/t/cgi-session-synchronization/146000/2 "2008-08-16T08:44:45Z")

</div>

Thanks for the help. It seems to be exactly what I need. I’m gonna need  
to do a little research concerning distributed ruby.  
-Patrick

---

<div class="post-metadata">

**Author:** ![lynchnco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c77e96/32.png) [@lynchnco](https://www.ruby-forum.com/u/lynchnco)\
**Post date:** [August 16, 2008, 5:35am UTC](https://www.ruby-forum.com/t/cgi-session-synchronization/146000/3 "2008-08-16T05:35:05Z")

</div>

> In one window I’m running \<Temp.rb\>  
> …  
> and in another window I’m running \<Temp2.rb\>  
> …

Patrick: I’m not familiar with handling CGI::Session directly at the  
moment, but if you have multiple ruby processes that you need to  
synchronize I’m sure you will need some form of, well… Interprocess  
communication. You could even use a shared file to somehow synchronize  
the work of the two processes, but maybe the best option would be to  
investigate ruby standard Drb library :  
[http://chadfowler.com/ruby/drb.html](http://chadfowler.com/ruby/drb.html)

greets
