FASTCGI bugs

Q&A's, tips, howto's
Locked
dexter
Posts: 74
Joined: Fri Nov 11, 2011 12:55 am

FASTCGI bugs

Post by dexter »

I am testing fastcgi with all kind of thing

Now I met the first problem , it seems newlisp eval-string will change %; to be none.
here is

Code: Select all

<%
(print "Content-type: text/html\r\n\r\n")
 
;(module "web.lsp")
;(Web:send-headers)
 

%>

<html>
<body>
<div style ="height:30px;width:100%; background:black;"></div>
<div>
<%
    (print (string "It works newlisp with module web " (date)) )
%>

</div>

</body>
</html>

It will output like this:

Code: Select all

<html>
<body>
<div style ="height:30px;width:100It works newlisp with module web Tue Nov 15 20:07:16 2011

</div>

</body>
</html>

you see, width:100%;backgound.... to width:100
why?
newlisp will change %; ??

I use put-page code from module CGI ,I think this code is ok

Code: Select all

(define (put-page file-name , page start end)
    (set 'page (read-file file-name))
    (set 'start (find "<%" page))
    (set 'end (find "%>" page))
    (while (and start end)
        (print (slice page 0 start))
        (eval-string (slice page (+ start 2) (- end start 2)) MAIN (print   (last-error)))
        ;(if-not (nil? err-ret)   (print (string err-ret)))
        (set 'page (slice page (+ end 2)))
        (set 'start (find "<%" page))
        (set 'end (find "%>" page)))
    (print page))



https://github.com/guu/newlisp-fastcgi/ ... r/fcgi.lsp

sunmountain
Posts: 39
Joined: Tue Mar 15, 2011 5:11 am

Re: FASTCGI bugs

Post by sunmountain »

There is probably no bug there.
Are you using FCGI_printf ?
Then % starts a format specifier, which might eventually misinterpreted by the underlying vfprintf implementation.

You could try to mask the % with another %, so writing something like this:

Code: Select all

<%
(print "Content-type: text/html\r\n\r\n")

;(module "web.lsp")
;(Web:send-headers)


%>

<html>
<body>
<div style ="height:30px;width:100%%; background:black;"></div>
<div>
<%
    (print (string "It works newlisp with module web " (date)) )
%>

</div>

</body>
</html>
Take a look here.

dexter
Posts: 74
Joined: Fri Nov 11, 2011 12:55 am

Re: FASTCGI bugs

Post by dexter »

True
thanks

But it's not perfect if user need change % to %% by hand

So I add (replace "%" str "%%")

continue testing

sunmountain
Posts: 39
Joined: Tue Mar 15, 2011 5:11 am

Re: FASTCGI bugs

Post by sunmountain »

But it's not perfect if user need change % to %% by hand
That is not neccessary if you take FCGI_puts as underlying "printer".

dexter
Posts: 74
Joined: Fri Nov 11, 2011 12:55 am

Re: FASTCGI bugs

Post by dexter »

hmm...

First I used FCGI_puts

then it is not perfect too, it'll add a \n after everyline

Sot last

I use FCGI_putchar to do everything.

I hope FCGI_putchar wont be slow.

:)

sunmountain
Posts: 39
Joined: Tue Mar 15, 2011 5:11 am

Re: FASTCGI bugs

Post by sunmountain »

Perhaps you could just create your own function, which takes care of all the issues,
or you use define-macro, to reduce the runtime overhead.

Using a putchar on a string means you need to iterate over a list of chars,

Code: Select all

printf("%s\n","Hello, World!")
is one call (one library call), putchar would need 14 calls, not to mention the work needed to extract
every char out of the string.

So the question is: how long do call FastCGI fast ?

dexter
Posts: 74
Joined: Fri Nov 11, 2011 12:55 am

Re: FASTCGI bugs

Post by dexter »

actually

it is not slowly as we thought

I used webbench to test

webbench -t 10 -c 1000 url

I did not see the different speed between printf and putchar

maybe it is the same speed ?

I dont know how long FASTCGI calls by the way

And yes, I can write a function to get libfcgi's stdin stdout etc handles
so that I can use "fwrite" "fprintf" to work. better

But if I do that, it means I need to edit the libfcgi

Which I dont think it is important, cause If somebody really want to create a web site by runnig newlisp with fatcgi mode
He can do it in many ways

Such as complie a new version of newlisp , include fcgi_stdio.h to wrapper the basic C functions to work like fastcgi
I think it is possible and a very easy way
But if lutz can work on that, I think he'll create a perfect newlisp-fcgi,
He knows everything about newlisp.

Second
He can you printf ,which means FCGI_printf ,just need a little focus on % to %%, it is easy,too
and everyone can do it right now

To be honset with you
I am a bit lazy
And for now ,I did not see the lower speed because of putchar

my fastcgi code runnig even faster than php , on webbench test results
One newlisp fastcgi process faster than 10 php-cgis ,Cool ,right?
on my mac book 466

So I may not want to change putchar to printf ,or create some own functions now

LOL

Locked