logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Coding & Scripting Corner View previous topic :: View next topic
Reply to topic   Topic: mod_fcgid/c (apache, windows, xampp) getenv not working?
Author
blubber



Joined: 29 Mar 2009
Posts: 2

PostPosted: Sun 29 Mar '09 7:11    Post subject: mod_fcgid/c (apache, windows, xampp) getenv not working? Reply with quote

Hi, I'm using some very trivial "Hello World" C example to determine how to get a fastcgi working and after a couple of hours trying I finally got it running (compiled with VS2008SP1) and I'm pretty amazed by the speed and the usage of resources. One process is spawned, stays up and I even got some internal variables incremented (some trivial printf("call %d<br />", i++); thing), so I'm pretty certain, that I haven't done anything wrong regarding the configuration. But now comes the fun part: No "getenv" call gives me ANY! valid pointer in return. I always get "NULL" even for the more common ones like "TMP", "SERVER_NAME", "FCGI_DATA_LENGTH", "HTTP_CONTENT_LENGTH", "CONTENT_LENGTH". However everything works, if I just create a normal CGI binary.

Just to validate my code is not totally screwy I uploaded it to some shared hosting web space (apache/linux), compiled it and it runs like a charm (however I would prefer to develop on Windows if possible).

Anyone familiar with this kind of behavior? Could I have done anything wrong compiling and using libfcgi.dll/libfcgi.lib from fastcgi.com?

I apologize, if I have done any amateurish and obvious mistakes.. Any hint would be really appreciated!
Back to top
tdonovan
Moderator


Joined: 17 Dec 2005
Posts: 611
Location: Milford, MA, USA

PostPosted: Sun 29 Mar '09 18:52    Post subject: Reply with quote

I see this same problem if I don't compile libfcgi.dll and my fastcgi program using the same version of the compiler.
If I use Visual Studio 2008 (VC9) for both, I then get all the CGI variables OK.

FYI - I buit libfcgi.dll with VC9 on the command line like this:
    * Download the current development kit from http://www.fastcgi.com and un-tar it.

    * Open a Visual Studio 2008 Command prompt.

    * Change to the fcgi-2.4.0\libfcgi subdirectory and use these two commands:
    (note that the long CL command line will wrap)
    Code:
    CL /LD /MD /O2 /Oi /arch:SSE2 /Zi /Felibfcgi.dll /DNDEBUG /DWIN32 /D_CONSOLE /DLIBFCGI_EXPORTS /D_USE_32BIT_TIME_T /D_CRT_SECURE_NO_WARNINGS /D_SCL_SECURE_NO_WARNINGS /I..\include fcgiapp.c fcgi_stdio.c os_win32.c fcgio.cpp Ws2_32.lib

    MT -manifest libfcgi.dll.manifest -outputresource:libfcgi.dll;2
I used the libfcgi.dll that this creates with Apache 2.2.11 (also built with VC9) on Windows and it works OK for me.

It is probably a good idea to compile your own fastcgi program with /D_USE_32BIT_TIME_T too, because VC8 and VC9 will use 64-bit time unless you tell it not to.

Apparently, Microsoft changed how environment variables are stored between VC6 and VC8/VC9. If you have a mis-match between your program and libfcgi.dll, they can't be retrieved.

Hope this helps,
-tom-
Back to top
sauda



Joined: 28 Aug 2009
Posts: 8
Location: India

PostPosted: Fri 28 Aug '09 6:34    Post subject: issues in building libfcgi.dll Reply with quote

Hi,

I'm novice to FastCGI, Dll's, VC++ 6.0 and stuff...

I downloaded the .tar as mentioned here by Tom, but I'm not able to create the dll!!

1) Which location should i place the unzippped content?

2) How to open a command prompt for MS VC++ 6.0 or MS .Net 2003?
(I have a dump of MC VC++ 6.0 and installed version of MS .Net 2003)

3) How to get the commands (mentioned by Tom) working to create libfcgi.dll or libfcgi.lib using MS VC++ 6.0 or MS .Net 2003?

4) The code I'm trying to compile is:
int main(int argc, char* argv[])
{
while (FCGI_Accept() >= 0)
{
printf("Hello World!\n");
}
return 0;
}
What all should be done by me to get this to work?
In sense, what are the changes to the code to include the header files related to FastCGI and to include the libfcgi.dll in the IDE?
Back to top
sauda



Joined: 28 Aug 2009
Posts: 8
Location: India

PostPosted: Fri 28 Aug '09 7:55    Post subject: issues in linking libfcgi.dll Reply with quote

hi,

I managed to create libfcgi.dll and libfcgi.lib using libfcgi.dsp provided in the tar file using MS .Net 2003.

But when I try to build the sample code mentioned earlier, I still get the linker errors stating "unresolved external symbol for FCGI_Accept() and printf()"

Can someone help me proceed?
Back to top
sauda



Joined: 28 Aug 2009
Posts: 8
Location: India

PostPosted: Fri 28 Aug '09 14:21    Post subject: fastcgi application Reply with quote

Hi,

I could successully compile and execute the Fastcgi application.

Now, I have problem deploying mod_fastcgi.dll in Apache 2.2.13.
1) I have downloaded "mod_fastcgi-2.4.2-AP20.dll" from fastcgi.com
2) Added the module in modules directory and renamed it to mod_fastcgi.so
3) Added a line in the configuration file httpd.conf stating "LoadModule fastcgi_module modules/mod_fastcgi.so"
4) Now, if I start Apache manually, I get a screen for a fraction of a second and then it vanishes! Apache does not start...

Can some one let me know whats going wrong?
Back to top
glsmith
Moderator


Joined: 16 Oct 2007
Posts: 2268
Location: Sun Diego, USA

PostPosted: Fri 28 Aug '09 20:10    Post subject: Reply with quote

no need to rename .dll to .so since in windows .so is a dll
LoadModule fastcgi_module modules/mod_fastcgi.dll

That module you grabbed however is for Apache 2.0.x.
Much different APR in that old beast than is in 2.2.13
I'd imagine you will see as much in the Windows Event viewer when you launched Apache e.g. faulting module libapr-1.dll or similar.

2.0.63 uses APR 0.9.whatever-it-is
2.2.13 uses APR 1.3.8, APR-Util 1.3.9

So, while this may be worth trying
http://www.fastcgi.com/dist/mod_fastcgi-2.4.6-AP22.dll

The problem is that (last win32 build) predates APR 1.3.0 released June 3, 2008.

You may simply have to build the module using this source
http://www.fastcgi.com/dist/mod_fastcgi-SNAP-0811090952.tar.gz
which is the only thing I see distributed after that date.
Back to top
sauda



Joined: 28 Aug 2009
Posts: 8
Location: India

PostPosted: Mon 31 Aug '09 7:05    Post subject: deploying fastcgi module in apache 2.2.13 Reply with quote

Hi Smith,

Thank you so much for the reply. I used the "mod_fastcgi-2.4.6-AP22.dll" mentioned by you and got apache to start!!

But I'm inquisitive to understnad
1) The difference between the dll's namely, mod_fastcgi-2.4.6-AP22.dll and mod_fastcgi-2.4.2-AP20.dll.
2) I could not find anything related to Apache in Windows event viewer when Apache failed to start earlier.

Can you please elaborate and help me understand?
Back to top
sauda



Joined: 28 Aug 2009
Posts: 8
Location: India

PostPosted: Mon 31 Aug '09 11:47    Post subject: accessing fastcgi application using apache Reply with quote

Hi,

I have one more question:
When I deployed the FastCGI application in the cgi-bin directory of Apache, I got a error message stating:
"The application has failed to start because "libfcgi.dll was not found. Re-installing the application may fix the problem".

When I copied the libfcgi.dll also to the cgi-bin directory, the error got resolved and I was able to access the application smoothly.

Is this correct to copy the dll as well to the cgi-bin directory or something went wrong in building/compiling of the application?
Back to top
glsmith
Moderator


Joined: 16 Oct 2007
Posts: 2268
Location: Sun Diego, USA

PostPosted: Mon 31 Aug '09 19:15    Post subject: Reply with quote

No, it is correct to need to supply dll however typically they should go in the Apache /bin folder. zlib1.dll is there for mod_deflate. If your use mod_security you must do that with libxml2.dll as well.

As for #1, as I said, the APR (Apache Portable Runtime) is much different. The files are named a bit differently as well. some calls the module makes can be different cause during the build process, some things will not get turned on in one that are in the other. Sometimes just between minor version changes this can be the case. An example would mod_fcgid, when the APR went from 1.2 to 1.3 that module quit working. Hard for me to explain because I am not horribly familiar with the exact details.

#2, this can happen if Apache crashes prior to opening up any logging pipes. The event viewer is the failsafe (supposedly) since one would think that is the OS's doings, but not always and I really do not understand that at all, but I've seen it happen more than once.
Back to top
sauda



Joined: 28 Aug 2009
Posts: 8
Location: India

PostPosted: Tue 01 Sep '09 6:53    Post subject: FastCGI binaries - Application Code Reply with quote

Hi Smith,

Thank you for providing the details. I have another query!

When I deployed one of my applications I could see that the application homepage did not get loaded completely.
Additionally, when I checked the code written by my application using "View Source" of the page, I see that only half of the code had been written.

The same application works fine if it is built as CGI binary!

Am I missing out any config params for this?
Back to top
glsmith
Moderator


Joined: 16 Oct 2007
Posts: 2268
Location: Sun Diego, USA

PostPosted: Tue 01 Sep '09 7:16    Post subject: Reply with quote

I honestly do not know enough of about fastcgi to answer that. Someone here should know .. just may take a few days to hear from them.
Back to top
sauda



Joined: 28 Aug 2009
Posts: 8
Location: India

PostPosted: Tue 01 Sep '09 8:27    Post subject: Reply with quote

Hi Smith,

Thanks for your help so far!

I've posted a new topic for the same. Let me wait if someone can answer it..
Back to top


Reply to topic   Topic: mod_fcgid/c (apache, windows, xampp) getenv not working? View previous topic :: View next topic
Post new topic   Forum Index -> Coding & Scripting Corner