Just starting out? Need help? Post your questions and find answers here.
ruyi7952
User
Posts: 11 Joined: Thu Jan 21, 2010 5:27 pm
Post
by ruyi7952 » Thu Jan 21, 2010 5:43 pm
my webserver baseon the Apache(Apache/2.2.14 (Win32) DAV/2 mod_fcgid/2.3.4 mod_autoindex_color PHP/5.3.1).the libfcgi it's "2.4.1 snap-2009" and compiled by VC6 SP6.
but this code can compiled and runing console,but it's do not working apache with fastcgi mode.
Code: Select all
OpenConsole()
If OpenLibrary(0, "libfcgi.dll")
*FCGI_Accept = GetFunction(0, "FCGI_Accept")
CRLF.s = Chr(13)+Chr(10)
EndIf
;-- Initalize our counter before the fcgi main loop
count.l
;
; '-- Loop until fcgi says otherwise
While CallFunctionFast(*FCGI_Accept) >= 0
count=count+1
;for http header
Print("Content-type: text/html" + CRLF)
Print(CRLF)
; http header EOF
PrintN("<html><head><title>FastCGI PBEcho</title></head><body>")
PrintN("<h1>FastCGI PureEcho</h1><br/>")
PrintN("Request Number:" + Str(count) + "<br/>")
PrintN("</html>")
Wend
CloseLibrary(0)
CloseConsole()
BTW an c code worked.
Code: Select all
//
// FastCGI 环境测试代码。
//
#include "fcgi_stdio.h"
#include <stdlib.h>
#include <string.h>
int main(void)
{
// 初始化
int num = 0;
// WEB事件
while (FCGI_Accept() >= 0) {
printf("Content-type: text/html\r\n\r\n");
printf("<html>\nCOUNT:%d\n</html>", ++num);
}
// WEB事件结束
return 0;
}
why???
please help me
thanks you.
ruyi7952
ruyi7952
User
Posts: 11 Joined: Thu Jan 21, 2010 5:27 pm
Post
by ruyi7952 » Thu Jan 21, 2010 6:51 pm
apache error.log
[Fri Jan 22 01:45:42 2010] [notice] Digest: generating secret for digest authentication ...
[Fri Jan 22 01:45:42 2010] [notice] Digest: done
[Fri Jan 22 01:45:43 2010] [notice] Apache/2.2.14 (Win32) DAV/2 mod_fcgid/2.3.4 mod_autoindex_color PHP/5.3.1 configured -- resuming normal operations
[Fri Jan 22 01:45:43 2010] [notice] Server built: Nov 11 2009 14:29:03
[Fri Jan 22 01:45:43 2010] [notice] Parent: Created child process 5836
[Fri Jan 22 01:45:43 2010] [notice] Digest: generating secret for digest authentication ...
[Fri Jan 22 01:45:43 2010] [notice] Digest: done
[Fri Jan 22 01:45:44 2010] [notice] Child 5836: Child process is running
[Fri Jan 22 01:45:44 2010] [notice] Child 5836: Acquired the start mutex.
[Fri Jan 22 01:45:44 2010] [notice] Child 5836: Starting 150 worker threads.
[Fri Jan 22 01:45:44 2010] [notice] Child 5836: Starting thread to listen on port 80.
[Fri Jan 22 01:46:22 2010] [notice] Parent: child process exited with status 3221225477 -- Restarting.
[Fri Jan 22 01:46:22 2010] [notice] Digest: generating secret for digest authentication ...
[Fri Jan 22 01:46:22 2010] [notice] Digest: done
why purebasic do not work??
why C worked??
Rook Zimbabwe
Addict
Posts: 4322 Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:
Post
by Rook Zimbabwe » Thu Jan 21, 2010 8:41 pm
Honestly... I mean we know you are logging this!
What port did you tell it to listen to?
ruyi7952
User
Posts: 11 Joined: Thu Jan 21, 2010 5:27 pm
Post
by ruyi7952 » Thu Jan 21, 2010 10:14 pm
hi Rook Zimbabwe,
thanks for your reply.
fastcgi it's double mode, stdio mode link cgi and app mode link php-cgi. app needed list a port,stdio do not need.
it's a bug for purebasic I/O function.
i have tested use printf() in gcc vc icc and d working ,but in purebasic printf() it's do not work.
i hava use FCGI_puts() function in libfcgi.dll, the purebasic codes it's working.
c4s
Addict
Posts: 1981 Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany
Post
by c4s » Thu Jan 21, 2010 10:27 pm
ruyi7952 wrote: i have tested use printf() in gcc vc icc and d working ,but in purebasic printf() it's do not work.
PrintF() isn't a PureBasic command or are you talking about PrintN()?
Maybe Print("text" + #CRLF$) (or just #CR$ / #LF$) is doing what you want?
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
ruyi7952
User
Posts: 11 Joined: Thu Jan 21, 2010 5:27 pm
Post
by ruyi7952 » Thu Jan 21, 2010 11:06 pm
hi c4s
thanks for your reply.
yes,it's print().
but it's not work for fastcgi.
Code: Select all
OpenConsole()
If OpenLibrary(0, "libfcgi.dll")
*FCGI_Accept = GetFunction(0, "FCGI_Accept")
CRLF.s = Chr(13)+Chr(10)
EndIf
;-- Initalize our counter before the fcgi main loop
count.l
ASCIIZ.s = Space(10000)
;
; '-- Loop until fcgi says otherwise
While CallFunctionFast(*FCGI_Accept) >= 0
count=count+1
;for http header
Print("Content-type: text/html" + #CRLF$)
Print(#CRLF$)
; http header EOF
PrintN("<html><head><title>FastCGI PBEcho</title></head><body>")
PrintN("<h1>FastCGI PureEcho</h1><br/>")
PrintN("Request Number:" + Str(count) + "<br/>")
PrintN("</html>")
; '-- Tell fcgi we're exiting If called more than 10 times
; If count > 10
; CallFunctionFast(*FCGI_SetExitStatus, 0)
; CallFunctionFast(*FCGI_Finish)
; End
; ; EXIT DO
; EndIf
Wend
CloseLibrary(0)
CloseConsole()
Rook Zimbabwe
Addict
Posts: 4322 Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:
Post
by Rook Zimbabwe » Fri Jan 22, 2010 2:53 am
Code: Select all
Print("Content-type: text/html" + #CRLF$)
PrintN("")
; http header EOF
I would cheat and use that to go to the next line to start with.
I am looking at how this program tells the calling program whats happening... You may have to prototype to get teh proper return from the program. Do you know if the DLL was written in C++ or is a .NET component? You may have to use COMMate if that is the case...
ruyi7952
User
Posts: 11 Joined: Thu Jan 21, 2010 5:27 pm
Post
by ruyi7952 » Fri Jan 22, 2010 3:18 am
hi,Rook Zimbabwe.
FastCGI SDK from http://www.fastcgi.com,the libfcgi.dll compiled by vc6 sp6.
DLLAPI int FCGI_Accept(void);
Code: Select all
Print("Content-type: text/html" + #CRLF$)
PrintN("")
do not work...
ruyi7952
Trond
Always Here
Posts: 7446 Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway
Post
by Trond » Fri Jan 22, 2010 11:48 am
The whole point of fastcgi is that stdin/stdout is not used. You can't use PrintN().
When you use fastcgi in C, it replaces the default printf() with a special fastcgi function.
ruyi7952
User
Posts: 11 Joined: Thu Jan 21, 2010 5:27 pm
Post
by ruyi7952 » Fri Jan 22, 2010 11:58 am
hi Trond
thanks for your reply.
The fcgi_stdio Library: I/O Compatibility
The implementation for I/O compatibility is that the library fcgi_stdio.h contains macros to translate the types and procedures defined in stdio.h into the appropriate FastCGI calls. For example, consider a FastCGI program written in C containing the following line of code:
fprintf(stdout, "<H2>Aerobic Juggling</H2>/n");
fcgi_stdio.h
header file contains the macro
#define fprintf FCGI_fprintf
So the preprocessor translates the fprintf call into the following call:
FCGI_fprintf(stdout, "<H2>Aerobic Juggling</H2>/n");
FCGI_fprintf
takes the same arguments as fprintf.
The implementation of FCGI_fprintf tests the file to see if it is a normal C stream or a FastCGI stream, and calls the appropriate implementation.
The fcgi_stdio.h header file contains macros to translate calls to all ISO stdio.h routines (and all conventional Posix additions, such as fileno, fdopen, popen, and pclose) into their FastCGI equivalents
Rook Zimbabwe
Addict
Posts: 4322 Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:
Post
by Rook Zimbabwe » Fri Jan 22, 2010 5:09 pm
FCGI_fprintf(stdout, "<H2>Aerobic Juggling</H2>/n");
I think the " stdout " is the issue... isn't the console opened in PB a specialized window???
ruyi7952
User
Posts: 11 Joined: Thu Jan 21, 2010 5:27 pm
Post
by ruyi7952 » Fri Jan 22, 2010 5:43 pm
I don't know .
Fred
Administrator
Posts: 18162 Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:
Post
by Fred » Fri Jan 22, 2010 6:34 pm
No, it's not, it should work.
ruyi7952
User
Posts: 11 Joined: Thu Jan 21, 2010 5:27 pm
Post
by ruyi7952 » Fri Jan 22, 2010 9:35 pm
hi Fred,
thanks for your replay.
you say work??how working???
please. :roll:
Trond
Always Here
Posts: 7446 Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway
Post
by Trond » Sat Jan 23, 2010 2:03 pm
Fred wrote: No, it's not, it should work.
It should absolutely not work. It's totally impossible.
Why didn't anyone read my post?
FCGI doesn't use stdout/stdin . FCGI uses a socket.
The implementation of FCGI_fprintf tests the file to see if it is a normal C stream or a FastCGI stream, and calls the appropriate implementation.
If it is a FastCGI stream the appropriate implementation is to pack the message in a struct and send over the socket connection. Not using stdout.