Welcome to WebmasterWorld Guest from 54.160.163.163

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

How to run apache module before the php module?

     

jikker

3:52 am on Jan 14, 2013 (gmt 0)



Hi, everyone

I want ask an apache module question , hope you can help me, thanks.

I write the apache input filter module,
I want it log apache process pid and run before the php module,
but it always run after php,

I load apache module before the php module in http.conf, like

LoadModule first_filter_module /usr/lib/apache2/modules/mod_first_filter.so
AddInputFilter PidFilter .php
LoadModule php5_module /usr/lib/apache2/modules/libphp5.so

I try modify ap_hook_insert_filter function nOrder variable to APR_HOOK_FIRST, but it not work,
then I try modify ap_register_input_filter ftype variable to AP_FTYPE_RESOURCE, but it not work.

So, I try modify ap_hook_insert_filter function aszPre variable to "mod_php5.c", "mod_php.c", "libphp5.c",
because I don't make sure the php module real name, but it still not work...

How I need do something to make sure this module run before the php?

Please help me solve this problem, thanks all.

Eric

this is my source code

#include "httpd.h"
#include "http_config.h"
#include "http_request.h"
#include "http_protocol.h"
#include "ap_config.h"

#include "apr_general.h"
#include "apr_buckets.h"
#include "apr_lib.h"

#include "util_filter.h"

#include <time.h>

static const char pidFilterName[]="PidFilter";
module AP_MODULE_DECLARE_DATA pid_filter_module;

typedef struct
{
int bEnabled;
} PidFilterConfig;

static char* print_pid(char *filename, char *execute){
FILE *fp;
fp = fopen(filename,"a");
fprintf(fp,"%s pid: %d ,fpid: %d, time: %d\n", execute, (int)getpid(), (int)getppid(), time(NULL) );
fclose(fp);
return sql;
}

static apr_status_t pid_filter(ap_filter_t *f, apr_bucket_brigade *bb, ap_input_mode_t mode,
apr_read_type_e block, apr_off_t readbytes){
char *filename="/var/www/sql.log";
char *execute="apache pid filter: ";
print_pid(filename, execute);

int rv;
rv = ap_get_brigade(f->next, bb, mode, block, readbytes);
return rv;
}

static void *PidFilterInCreateServerConfig(apr_pool_t *p, server_rec *s)
{
PidFilterConfig *pConfig = apr_pcalloc(p, sizeof *pConfig);

pConfig->bEnabled = 0;

return pConfig;
}

static const char *PidFilterInEnable(cmd_parms *cmd, void *dummy, int arg)
{
PidFilterConfig *pConfig
= ap_get_module_config(cmd->server->module_config,
&pid_filter_module);
pConfig->bEnabled=arg;

return NULL;
}

static const command_rec PidFilterInCmds[] =
{
AP_INIT_FLAG(pidFilterName, PidFilterInEnable, NULL, RSRC_CONF,
"Run an input pid filter on this host"),
{ NULL }
};

static void PidFilterInsertFilter(request_rec *r)
{
PidFilterConfig *pConfig=ap_get_module_config(r->server->module_config,
&pid_filter_module);

if (!pConfig->bEnabled)
return;
static const char * const aszPre[] = { "mod_php5.c", "mod_php.c", "libphp5.c", NULL };
ap_add_input_filter(pidFilterName, aszPre, r, r->connection);
}

static void pid_filter_register_hooks(apr_pool_t *p)
{
static const char * const aszPre[] = { "mod_php5.c", "mod_php.c", "libphp5.c", NULL };
ap_hook_insert_filter(PidFilterInsertFilter, aszPre, NULL, APR_HOOK_FIRST - 1);
ap_register_input_filter(pidFilterName, pid_filter, NULL, AP_FTYPE_RESOURCE);
}

/* Dispatch list for API hooks */
module AP_MODULE_DECLARE_DATA pid_filter_module = {
STANDARD20_MODULE_STUFF,
NULL, /* create per-dir config structures */
NULL, /* merge per-dir config structures */
PidFilterInCreateServerConfig, /* create per-server config structures */
NULL, /* merge per-server config structures */
PidFilterInCmds, /* table of config file commands */
pid_filter_register_hooks /* register hooks */
};

lucy24

12:48 pm on Jan 14, 2013 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



It's much too late in the night for questions like this, but... don't Apache modules execute in the inverse order of loading? If I read your opening paragraph right, you're loading A before B when you should be loading B before A.

jikker

2:52 am on Jan 15, 2013 (gmt 0)



hi lucy24

thanks for your reply,
I change load module order to

LoadModule php5_module /usr/lib/apache2/modules/libphp5.so
LoadModule first_filter_module /usr/lib/apache2/modules/mod_first_filter.so
AddInputFilter PidFilter .php

and restart the apache,
but...still not work... orz

Actually, it's not too late, because I post this thread in the afternoon at taiwan. LOL
 

Featured Threads

Hot Threads This Week

Hot Threads This Month