LiteSpeed Technologies
Download Download     Blog Blog     Wiki Wiki     Forum Forum     Store     Contact Contact    

Go Back   LiteSpeed Support Forums > LiteSpeed Web Server > Install/Configuration > C/C++ FastCGI

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #21  
Old 06-14-2005, 01:21 AM
fryk fryk is offline
Member
 
Join Date: Jun 2005
Posts: 16
Sure.

simple-test-script.php
Code:
<html><head><title>CGI C Example #3</title></head>
<body><h1>CGI C Example #3</h1>
<table border=2>

<?

$db = mysql_pconnect&#40;"localhost","root",""&#41; or die&#40;'konnekt'&#41;;
mysql_select_db&#40;"ht3"&#41; or die&#40;'db'&#41;;

$r = mysql_query&#40;"SELECT * FROM pages"&#41;;
if &#40;$r&#41;	
&#123;
	$nrows = mysql_num_rows&#40;$r&#41;;
	$num_fields = mysql_num_fields&#40;$r&#41;;
	
	printf&#40;"rows&#58; %i, cols&#58; %i

\n",$nrows,$num_fields&#41;;
	printf&#40;"<table border=2>\n"&#41;;

	while &#40; $row = mysql_fetch_array&#40;$r&#41; &#41;
	&#123;
		printf&#40;"<tr>"&#41;;
		for&#40;$j = 0; $j < $num_fields; $j++&#41;
		&#123;
			printf&#40;"<td>%s</td>", $row&#91;$j&#93; ? $row&#91;$j&#93; &#58; NULL"&#41;;
		&#125;
		printf&#40;"</tr>"&#41;;
		printf&#40;"\n"&#41;;
	&#125;

	printf&#40;"</table></body></html>\n"&#41;;
   mysql_free_result&#40;$r&#41;;

&#125;

mysql_close&#40;$db&#41;;

?>

</table></body></html>
simple-test-script.c
Code:
#include	<stdio.h>
#include	<mysql.h>
#include "fcgi_config.h"
#include <stdlib.h>
#include "fcgi_stdio.h"

int main &#40;&#41;
&#123;
	int	err = 0;
	MYSQL	dbase;

	if &#40;mysql_init&#40;&dbase&#41; == NULL&#41; err = 1;
	else
	&#123;		
		if&#40;mysql_real_connect&#40;&dbase,"localhost","root","","ht3",0,NULL,0&#41; == NULL&#41; err = 1;
	&#125;
	if&#40;err&#41;
	&#123;
		printf&#40;"

Error connecting to database</body></html>\n"&#41;;
		exit&#40;0&#41;;
	&#125;


	//
	// B E G I N   R E Q U E S T
	// 


    while &#40;FCGI_Accept&#40;&#41; >= 0&#41;
    &#123;
		char		sqlbuff&#91;255&#93;;
		MYSQL_RES	*result;
		
		printf&#40;"Content-type&#58; text/html\r\n\r\n"&#41;;
		printf&#40;"<html><head><title>CGI C Example #3</title></head>\n"&#41;;
		printf&#40;"<body><h1>CGI C Example #3&#58; %i</h1>\n",getpid&#40;&#41;&#41;;
	
		sprintf&#40;sqlbuff,"SELECT * FROM pages"&#41;;
		if&#40;mysql_real_query&#40;&dbase,sqlbuff,strlen&#40;sqlbuff&#41;&#41;&#41;
		&#123;
			printf&#40;"

SQL error</body></html>\n"&#41;;
			exit&#40;1&#41;;
		&#125;
		
		result = mysql_store_result&#40;&dbase&#41;;
		if&#40;result&#41;
		&#123;
			int			i, j, num_fields, nrows;
			MYSQL_ROW	row;;
			
			nrows = mysql_num_rows&#40;result&#41;;
			num_fields = mysql_num_fields&#40;result&#41;;
			
			printf&#40;"rows&#58; %i, cols&#58; %i

\n",nrows,num_fields&#41;;
			printf&#40;"<table border=2>\n"&#41;;

			while &#40; row = mysql_fetch_row&#40;result&#41; &#41;
			&#123;
				printf&#40;"<tr>"&#41;;
				for&#40;j = 0; j < num_fields; j++&#41;
				&#123;
					printf&#40;"<td>%s</td>", row&#91;j&#93; ? row&#91;j&#93; &#58; "NULL"&#41;;
				&#125;
				printf&#40;"</tr>"&#41;;
				printf&#40;"\n"&#41;;
			&#125;

			printf&#40;"</table></body></html>\n"&#41;;

			mysql_free_result&#40;result&#41;;
			free&#40;result&#41;;
		&#125;
		else
		&#123;
			printf&#40;"No entries</body></html>\n"&#41;;
		&#125;

    &#125; /* while */
    
    mysql_close&#40;&dbase&#41;;

    return 0;
&#125;
"SELECT * FROM pages" returns 4 rows / 5 short columns each.

I got ubuntu:
Code:
root@fryk&#58;/var/www # uname -a
Linux fryk 2.6.10-5-386 #1 Tue Apr 5 12&#58;12&#58;40 UTC 2005 i686 GNU/Linux
on p4 2.xghz 512ram

Apache2 run just from apt-get install + mod_php + mod_fastcgi (-processes 10 - same as lsws).
Lsws standard with c fastcgi as described in previous posts (php fastcgi is built in - as I get it).

I typically measured it with
Code:
ab -n 20000 -c 50 PATH
Reply With Quote
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
FastCGI spawning more processes jooray Bug Reports 7 01-02-2007 03:50 PM
FastCGI > LSAPI ? Jetro Feedback/Feature Requests 6 10-19-2005 09:48 AM
503 Service Unavailable - while setting up Perl FastCGI nigel CGI/Perl/Python 1 02-15-2005 06:15 AM
FastCGI : SCRIPT_FILENAME vs. PATH_TRANSLATED bogus Install/Configuration 2 03-21-2004 11:06 AM
FastCGI responders bogus Install/Configuration 3 12-08-2003 09:31 AM


All times are GMT -7. The time now is 10:36 AM.



- Archive - Top
© Copyright 2003-2011 LiteSpeed Technologies, Inc. All rights reserved. Privacy Policy.