Is there any way to have global variables or global data in v8cgi?

17 views
Skip to first unread message

Nilima Chavan

unread,
Aug 26, 2010, 7:29:43 AM8/26/10
to v8cgi
Is there any way to have global variables or global data in v8cgi?

Ondřej Žára

unread,
Aug 27, 2010, 11:12:30 AM8/27/10
to v8...@googlegroups.com


2010/8/26 Nilima Chavan <nilima...@gmail.com>

Is there any way to have global variables or global data in v8cgi?


Yes, by writing "global.myVariable = 123;"

Note, however, that global variables are generally considered a bad practice.


Sincerely,
Ondrej Zara
 
--
You received this message because you are subscribed to the Google Groups "v8cgi" group.
To post to this group, send email to v8...@googlegroups.com.
To unsubscribe from this group, send email to v8cgi+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/v8cgi?hl=en.


Nilima Chavan

unread,
Sep 15, 2010, 3:08:41 AM9/15/10
to v8cgi
But global object is per HTTP request right?
So will the data stored in global object will be preserved across the
requests?

Even if we use reuse_context functionality, still for each request,
all the global object properties get clears.

- Nilima


On Aug 27, 8:12 pm, Ondřej Žára <ondrej.z...@gmail.com> wrote:
> 2010/8/26 Nilima Chavan <nilima.cha...@gmail.com>
>
> > Is there any way to have global variables or global data in v8cgi?
>
> Yes, by writing "global.myVariable = 123;"
>
> Note, however, that global variables are generally considered a bad
> practice.
>
> Sincerely,
> Ondrej Zara
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "v8cgi" group.
> > To post to this group, send email to v8...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > v8cgi+un...@googlegroups.com <v8cgi%2Bunsu...@googlegroups.com>.

Ondřej Žára

unread,
Sep 15, 2010, 7:07:46 AM9/15/10
to v8...@googlegroups.com

2010/9/15 Nilima Chavan <nilima...@gmail.com>

But global object is per HTTP request right?
So will the data stored in global object will be preserved across the
requests?

Even if we use reuse_context functionality, still for each request,
all the global object properties get clears.


Yes, exactly. In CGI scenario, for instance, every request means new single v8cgi process - there is no universal, reliable and generic way to preserve data across requests. An optimal solution seems to be memcached...


Sincerely,
Ondrej Zara

 
- Nilima


On Aug 27, 8:12 pm, Ondřej Žára <ondrej.z...@gmail.com> wrote:
> 2010/8/26 Nilima Chavan <nilima.cha...@gmail.com>
>
> > Is there any way to have global variables or global data in v8cgi?
>
> Yes, by writing "global.myVariable = 123;"
>
> Note, however, that global variables are generally considered a bad
> practice.
>
> Sincerely,
> Ondrej Zara
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "v8cgi" group.
> > To post to this group, send email to v8...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > v8cgi+un...@googlegroups.com <v8cgi%2Bunsu...@googlegroups.com>.
> > For more options, visit this group at
> >http://groups.google.com/group/v8cgi?hl=en.
>
>

--
You received this message because you are subscribed to the Google Groups "v8cgi" group.
To post to this group, send email to v8...@googlegroups.com.
To unsubscribe from this group, send email to v8cgi+un...@googlegroups.com.

Bogdan Mart

unread,
Jul 15, 2013, 3:50:10 PM7/15/13
to te...@googlegroups.com, v8...@googlegroups.com
Is that same for FastCGI?

In particular I'd like to create online game and preserv "Game room" object in shared memory. 

среда, 15 сентября 2010 г., 14:07:46 UTC+3 пользователь ondras написал:

2010/9/15 Nilima Chavan <nilima...@gmail.com>
But global object is per HTTP request right?
So will the data stored in global object will be preserved across the
requests?

Even if we use reuse_context functionality, still for each request,
all the global object properties get clears.


Yes, exactly. In CGI scenario, for instance, every request means new single v8cgi process - there is no universal, reliable and generic way to preserve data across requests. An optimal solution seems to be memcached...


Sincerely,
Ondrej Zara

 
- Nilima


On Aug 27, 8:12 pm, Ondřej Žára <ondrej.z...@gmail.com> wrote:
> 2010/8/26 Nilima Chavan <nilima.cha...@gmail.com>
>
> > Is there any way to have global variables or global data in v8cgi?
>
> Yes, by writing "global.myVariable = 123;"
>
> Note, however, that global variables are generally considered a bad
> practice.
>
> Sincerely,
> Ondrej Zara
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "v8cgi" group.
> > To post to this group, send email to v8...@googlegroups.com.
> > To unsubscribe from this group, send email to

Stuart van Beek

unread,
Jul 15, 2013, 4:46:42 PM7/15/13
to te...@googlegroups.com, v8...@googlegroups.com
Wouldn't it be better to use sessions for that?

Ondřej Žára

unread,
Jul 16, 2013, 2:27:40 AM7/16/13
to te...@googlegroups.com, v8...@googlegroups.com
Yes, the same holds for FastCGI. In FastCGI, the process itself runs ifinitely, but every request gets a fresh JS context.

May I suggest switching to websocket, as opposed to Apache? There is a built-in websocket server module in TeaJS, which is far more suitable for a game room (there is also a sample websocket echo server to get you started...).


Sincerely,
Ondrej Zara



2013/7/15 Bogdan Mart <mart....@gmail.com>

--
You received this message because you are subscribed to the Google Groups "TeaJS (formerly v8cgi)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to teajs+un...@googlegroups.com.
To post to this group, send email to te...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/teajs/f08dd73b-0b34-48d6-ada7-03e2e17c08f0%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
+------------------+
|tn=b.             |
|p==n              |
|+j1               |
|=+                |
|1          #  ##  |
|           # #    |
|           #  ##  |
|        #  #    # |
|         ##   ##  |
+------------------+
 jsstyle.github.com
Reply all
Reply to author
Forward
0 new messages