PB Interpreter » Use PB instead of PHP or Perl for websites!

Developed or developing a new product in PureBasic? Tell the world about it.
User avatar
John Puccio
User
User
Posts: 26
Joined: Fri Jun 12, 2009 6:56 am
Location: My Keyboard

Post by John Puccio »

And, great idea!

You have my vote. I am very interested in this. I run a server out of my home but it's not Apache. It's just a test bed for my software projects, nothing special. I visited the links you posted. Both the counter and the index I had to load twice. They both worked fine on the second try.

Keep working on this idea! Call it PBWeb or PB.Net :D I like the name Ivory. 99.9% Pure LOL! But only americans would "get it".
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

Thanks for the great feedback.

In fact, the code works with every webserver that supports CGI (Common Gateway Inferface). CGI is designed to work with 3rd party apps, no matter if you use PureBasic, C++, Delphi, etc...

The 3rd party app only has to read from stdin and write to stdout.

The links you mentioned may work, but I don't care about them any more. I made them just to demonstrate that "it works", and they were made with version 1.0 of this interpreter.
Meantime, I have published 1.1 with caches the created executables, so the chance that you must load twice is veeery low.

Yeah, I'll keep working on this idea as I use this on my on websites now. I even finished a version 1.2, but it only has improvements regarding incoming program parameters (1.0 and 1.1 don't recognize the last parameter as Apache passes "-w -f -c" as one parameter with trailing #CRLF$).
Unfortunately, I only can test this interpreter with Apache on Linux. In order to use it on other systems (IIS, Windows, other systems), you must adjust the code according to the desired system. That's why I made this code available for the public.


Errr... What do you mean with, "only Americans would 'get it'"?
PB 4.30

Code: Select all

onErrorGoto(?Fred)
User avatar
John Puccio
User
User
Posts: 26
Joined: Fri Jun 12, 2009 6:56 am
Location: My Keyboard

Post by John Puccio »

Your Welcome!

Ivory is a brand of soap sold here in the USA. The manufacturer claims that it is 99.9% Pure soap. It's so pure that it floats in water. Calling your project Ivory is kind of a joke because it's written in Pure and you can code the web in Pure.. So it's kind of like Ivory soap 99.9% Pure! I'm not sure you guys have Ivory soap in Europe. So a european might not understand the joke.

I'll take a look at your project this weekend and see if I can use it with my server. I have a collection of server software that I can use. This might be a good project for the Atomic Web Server written by AlphaSND and modified by others. This might turn into a nice PB community project. I would be happy to help with testing. Maybe someone has an idea for a client side PB interpreter. If we had that we would not need Java either. I'm pretty sure someone on here did some client side stuff already.

John P.
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Post by Rescator »

Maybe you should call it PB CGI or something along those lines?

Oh! And does it support FastCGI?
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

> Ivory is a brand of soap sold here in the USA
Oh yes, remember, we had that in this thread. No I've never heard of any soap called "Ivory". I don't think it exists here, at least not in Germany.

> a client side PB interpreter
Theoretically, you can also use this on your client side. Simply modify the registry to open every *.pb-file with the PB Interpreter and it does the rest (after some slight modifications).
But somehow this doesn't make sense, since on the client side, you could simply run a compiled EXE. The idea of the interpreter is that it is server side, because a server is a machine where no human sits behind to handle anything. Nobody has to care about the server, since the webserver automatically does everything.
Bringing PureBasic to every client PC in order to replace JAVA is senseless, as you can then run the compiled EXE directly. No runtime-compilation neccessary.

I don't know if I can make you the point clear, because I don't know how to express my opinion.

> PB CGI
My very first intention was to call it "PB Interpreter", since it is the source file that is only needed. If you modify it, this also affects the program that is generated out of it.
Knowing that it is not a real interpreter, I considered to rename it to something like "PureCGI", but there's alredy a UserLib with that name and then I got irritated.
Well, I will think about this big naming issue, since some of you seem to find it really funny if I called it "Ivory".
Ivory, translated to german, means "Elfenbein" and Elfenbein is the material of which the large... teeth... of an elephant consists. So ivory is a very precious raw material.

> does it support FastCGI
Not yet. If I recall correctly, 3rd party apps must run all the time and only once to be considered as FastCGI. It's similar to the PB compiler and its /STANDBY-parameter: the compiler is started once and waits for multiple/different inputs/requests to genrate multiple outputs. It's faster, because there doesn't have to be one instance for every request.

I tried to achieve this, but as far as I know, FastCGI is not so popular any more. Furthemore, I was unable to get FastCGI on my Linux-Server running, so I discarded this plan. (I am very new to Linux and had to learn EVERYTHING).

You may use this interpreter and enhance it by the ability to used through FastCGI.
PB 4.30

Code: Select all

onErrorGoto(?Fred)
User avatar
John Puccio
User
User
Posts: 26
Joined: Fri Jun 12, 2009 6:56 am
Location: My Keyboard

Post by John Puccio »

AND,

I tried to make your program work with one of my servers (windows based, not Apache) but had no luck. I know after some research that the server I tested does not pass SCRIPT_FILENAME. it's always passed as NUL by default. I know this from looking in the source. In any case I started experimenting. Seems like PB does CGI pretty well.

Code: Select all


;- CGI test example using purebasic

; 1  compile as CGItest.cgi
;    or rename CGItest.exe to CGItest.cgi 
;
; 2  copy to cgi-bin directory

; 3  create test.html that contains 1 line like this
;    <!-- #exec cgi="CGItest.cgi" -->
;    you can put html code after this line

; 4  copy test.html to your html directory

OpenConsole() 

PrintN("<html>")
PrintN("<head>")
PrintN("<title>Welcome!</title>")
PrintN("</head>")

PrintN("<body bgcolor='black'>")

PrintN("<font face='verdana' color='blue'>")
PrintN("<h1>Welcome To My World On The Web</h1>")

;- The actual variable names on your server may be different

PrintN("<p>HTTP_USER_AGENT : " + GetEnvironmentVariable("HTTP_USER_AGENT") + "</p>"); browser type of the visitor 
PrintN("<p>PATH            : " + GetEnvironmentVariable("PATH")            + "</p>"); system path your server is running under 
PrintN("<p>SERVER_PORT     : " + GetEnvironmentVariable("SERVER_PORT")     + "</p>"); port number your server is listening on 
PrintN("<p>SERVER_SOFTWARE : " + GetEnvironmentVariable("SERVER_SOFTWARE") + "</p>"); server software you're using (e.g. Apache 1.3)  

If OpenFile(0, "hitcounter.txt") 
   hits=ReadLong(0) + 1 
   FileSeek(0, 0) 
   WriteLong(0, hits)
   PrintN("<h1>This page has been accessed " + Str(hits) + " times.</h1>")
Else 
   Print("hitcounter.txt cannot be opened") 
EndIf 

PrintN("</font>")

PrintN("<button type=submit><strong>Send It!</strong></button>");- button test


PrintN("</body>")
PrintN("</html>")

CloseConsole()
End

Sometimes you need to do stuff client side that is just not possible or practical to do on the server. What I was suggesting is an ActiveX PB module so we could run native PB code client side. I wasn't suggesting an entire PB installation on the client. That would be silly. But a scaled down client side PB interpreter that installs in the browser would be really neat! Kind of like VBScript but with better (not MicroSoft) syntax! :D

Todays websites are looking and feeling more like applications than websites. This is possible because of client side processing (java). The idea of write once run everywhere has always been appealing to developers. By contrast,the idea of having to learn many different technologies to accomplish a single task has always been very unappealing and messy. If we could have a PB client language, that would make PB a total solution. 1 problem 1 language. I really don't like Java much. By the way.. Your points were made very clear. No worries! :)

John P.
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

Seems as if you are using SSI (Server Side Includes), because of step 3 in your code.
I assume, SSI works somehow different and I don't kniw which environment variables are passed, if you work with SSI. Have a look at ExamineEnvironmentVariables() or the ProgramParameter()'s to see, if the file is passed.

You might try CGI (Common Gateway Interface). That means, you save your PureBasic-code als "test.cgi" in your cgi-bin, giving it chmod 755 (if you use Linux) and you write the path+filename of the interpreter in the first line:

Code: Select all

#!C:/yampp/purebasic/interpreter.exe


OpenConsole() 


; IMPORTANT: A CGI-PROGRAM MUST GENERATE A HTTP-HEADER!!!
PrintN("Content-Type: text/html")   ; this is the
PrintN("")                          ; http-header with traling empty-line


PrintN("<html>") 
PrintN("<head>") 
PrintN("<title>Welcome!</title>") 
PrintN("</head>") 

PrintN("<body bgcolor='black'>") 

PrintN("<font face='verdana' color='blue'>") 
PrintN("<h1>Welcome To My World On The Web</h1>") 

;- The actual variable names on your server may be different 

PrintN("<p>HTTP_USER_AGENT : " + GetEnvironmentVariable("HTTP_USER_AGENT") + "</p>"); browser type of the visitor 
PrintN("<p>PATH            : " + GetEnvironmentVariable("PATH")            + "</p>"); system path your server is running under 
PrintN("<p>SERVER_PORT     : " + GetEnvironmentVariable("SERVER_PORT")     + "</p>"); port number your server is listening on 
PrintN("<p>SERVER_SOFTWARE : " + GetEnvironmentVariable("SERVER_SOFTWARE") + "</p>"); server software you're using (e.g. Apache 1.3)  

If OpenFile(0, "hitcounter.txt") 
   hits=ReadLong(0) + 1 
   FileSeek(0, 0) 
   WriteLong(0, hits) 
   PrintN("<h1>This page has been accessed " + Str(hits) + " times.</h1>") 
Else 
   Print("hitcounter.txt cannot be opened") 
EndIf 

PrintN("</font>") 

PrintN("<button type=submit><strong>Send It!</strong></button>");- button test 


PrintN("</body>") 
PrintN("</html>") 

CloseConsole() 
End 
If you now type http://localhost/cgi-bin/test.cgi into your browser, the webserver calls the interpreter which compiles the code and returns its output.

Embedding a HTML-generating program in a .html-file is double work, you know what I want to say?
Last edited by AND51 on Wed Jun 17, 2009 6:27 pm, edited 1 time in total.
PB 4.30

Code: Select all

onErrorGoto(?Fred)
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

John Puccio wrote:Sometimes you need to do stuff client side that is just not possible or practical to do on the server. What I was suggesting is an ActiveX PB module so we could run native PB code client side. I wasn't suggesting an entire PB installation on the client. That would be silly. But a scaled down client side PB interpreter that installs in the browser would be really neat! Kind of like VBScript but with better (not MicroSoft) syntax! :D
Well, I only see 1 solution for this: Compile serverside and run the executable at the client's side.

1) A complete PB installation at the client side is tooooooo much overhead. Moreover, you could only use PB Demo version, as it is free for all.

2) I don't see a chance to even get a lite version of PB at the clients side. What you could leave away would be the manual and the example files and the IDE. But the remaining amount of data is still too much.

3) Even if you consider the way deswcribed in 1+2, you will be faced with the limitations of the Demoversion: No API, just 600-800 lines, always-on-debugger, etc.

In my opinion, a browser-plugin should upload a PB-code to the server. The server compiles it and passes the executable back to the client where it is executed. But obviously, it would be better, if the source code is stored server side too. This has 2 advantages: First, the plgin doesn't need to upload anything (it only tells the server how to compile: for windows, for linux, for mac, in 32 bits or 64 bits). Second, you cannot easily insert other codes to misuse the compiler.


// edit:
This solution requires at least 2 servers. A Linux server which could compile for Linux, a Windows server which compiles for Windows. And probably a Mac Server to support that platform. Still remaining would be all users who go online via mobile phone, too (like me).
Everybody must decide on his own, if this effort is worth it.
PB 4.30

Code: Select all

onErrorGoto(?Fred)
Tipperton
Addict
Addict
Posts: 1286
Joined: Thu Jun 19, 2003 7:55 pm

Post by Tipperton »

Sounds similar to a Java installation with it's JIT (Just In Time) compiler and run time environment.

The big difference is Java compiles to byte code which is then interpreted by a virtual machine, but this would compile to pure machine code.

That being said, you'll probably have to use a full dedicated server, or your own server since errant code could lead to crashes and other problems no hosting service would want on their systems.
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

Most hosting systems that allow you to run non-proven executables keep you within a virtual machine. So if you crash - you just crash yourself.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
John Puccio
User
User
Posts: 26
Joined: Fri Jun 12, 2009 6:56 am
Location: My Keyboard

Post by John Puccio »

Your program is great keep working on it.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

And51, keep on working on this one! Very nice!
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

Thanks for your feedback!
Yes, I'll keep on working on this, since I use this for productive reasons on my own server.
I'll notify you, when I release a new version or something else happens.

Thank you again! :D
PB 4.30

Code: Select all

onErrorGoto(?Fred)
superadnim
Enthusiast
Enthusiast
Posts: 480
Joined: Thu Jul 27, 2006 4:06 am

Post by superadnim »

are you using a cache? I see this could be prone to simple attacks.

:lol: should I bash the keyboard and give up?
:?
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

Yes, because this reduces compilation-time significantly.

I don't see any leaks, because every executable is only created once, if requested.

Visitor A calls your website => exe does not exist yet => exe is created
Visitor B calls your website => exe exists already
Visitor C calls your website => exe exists already
Visitor D calls your website => exe exists already
... and so on ...

You see, there is no executable per visitor, but per source file. But you can use -f parameter to enforce a re-compilation. This means, an executable is created only temporary. After it has been run, it is deleted automatically.
PB 4.30

Code: Select all

onErrorGoto(?Fred)
Post Reply