Standalones as CGI

Andre Garzia andre at andregarzia.com
Wed Aug 15 02:11:48 EDT 2007


And wait, there's one more thing...
since the standalone is running on X11 (Xvfb is X11...) it has access to the
'export snapshot' command.

I just made this little script:


ON startup

   put "You are" && $REMOTE_ADDR into fld 1

END startup


ON openstack

  write "Content-type: image/png" & cr & cr to stdout

  export snapshot from rect (the screenrect) to pngImg as PNG

  write pngImg to stdout

  quit

END openstack

This is my standalone named teste2. Now with the loader script from the
previous email, we're able to see what the standalone think of the display.
Go to

    http://www.andregarzia.com/cgi-bin/teste3.cgi

you'll see that this loads the standalone, it renders itself, takes a
snapshot of itself, and quits very fast. Since we're running no window
manager or nice graphical libraries, our stack has no border or title, but
yet, it runs and it is able to do marvelous things...

Just to prove that this is live, I've added a bit in the code to show your
own IP...

Now, we can use linux standalones and even generate images. What about this?

Cheers
andre
PS: it's now 3:11 AM... I will be going to sleep, this is what happens when
they leave me in the computer after midnight...



On 8/15/07, Andre Garzia <andre at andregarzia.com> wrote:
>
> Richard,
>
> I just spent the last three hours working this out for you. Not only
> because you're my friend but because I wanted to know if it was possible.
>
> short answer is: YES.
>
>
> What is the problem with linux standalones:
> They want to launch in graphical mode, they want to open the stack in X11.
>
>
> How we can prevent that?
> We can't.
>
>
> So, how do we solve it?
> 1) First install Xvfb (X11 Virtual Framebuffer server). This allows you to
> have an headless X11 server running, this means things are rendered on
> memory and not in an actual display. Our standalones will be just as happy
> running under Xvfb as they are running on X11+GTK.
>
>
> 2) After installing it, you need to leave it running on the server with a
> command such as:
>
>
>    Xvfb :1 -screen 0 800x600x8 &
>
>
> This command tells Xvfb to bind itself to display 1 and configure the
> first screen to 800x600 with 8bit depth. Not that this data will ever be
> displayed. The trailing & is unix-speak for "move this to the background and
> give me back my command line prompt".
>
>
> 3) Now, when Apache calls the CGI it uses it's own user and session to do
> that, so you need a script launcher for the standalone, a simple script that
> will tell where the X11 & Friends are and also which display to use. The one
> I tried here looks like this (ps: my standalone is named teste2).
>
>
> #!/bin/sh
>
>
> export DISPLAY=localhost:1
> export REV_GDK_PATH=/usr/lib/libgdk-x11-2.0.so.0
> export REV_GTK_PATH=/usr/lib/libgtk-x11-2.0.so.0
> export REV_GOBJECT_PATH=/usr/lib/libgobject-2.0.so.0
> export REV_SSL_PATH=/usr/lib/libssl.so.0.9.7
>
>
> ./teste2
>
> 4) To call the standalone, you just call this script, in my case I called
> it teste3.cgi. So if you go to http://andregarzia.com/cgi-bin<http://andregarzia.com/cgi-bin/teste3.cgi>
> /teste3.cgi <http://andregarzia.com/cgi-bin/teste3.cgi> you'll see a
> simple text output 'stdout' thats generated by the standalone.
>
>
> Tips & Tricks
>
> With script cgis we usually use the "put" command to send data back to the
> console/browser. With standalones this won't work. You need to send your
> data to stdout with something like:
>
>     write "hello, world!" to stdout
>
>
> So, in the end you can run standalones. Just some minor gotchas. Xvfb
> starts really fast, maybe you can even start it in your loader script and
> kill it after your standalone exits, don't know, anyway, if you control your
> server or are in a position to make requirements, you can require that Xvfb
> be running on the server.
>
>
> This would not be needed if RunRev team ships a linux engine that
> generates standalones where we can use the -ui command too.
>
> Hope this answer your question! :-)
>
>
> Andre
>
>
> On 8/15/07, Richard Gaskin < ambassador at fourthworld.com> wrote:
> >
> >
> > Have any of you successfully run a standalone as a CGI on a Linux
> > server?
> >
> > If so, how?
> >
> > --
> >   Richard Gaskin
> >   Managing Editor, revJournal
> >   _______________________________________________________
> >   Rev tips, tutorials and more: http://www.revJournal.com
> > _______________________________________________
> > use-revolution mailing list
> > use-revolution at lists.runrev.com
> > Please visit this url to subscribe, unsubscribe and manage your
> > subscription preferences:
> > http://lists.runrev.com/mailman/listinfo/use-revolution
> >
>
>



More information about the use-livecode mailing list