Apache Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsSystem AdministrationApache Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 14th, 2013, 02:03 AM
jikker jikker is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 1 jikker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 2 sec
Reputation Power: 0
Unhappy How to run apache module before the php module?

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
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                      */
};

Last edited by jharnois : January 31st, 2013 at 11:12 AM. Reason: Added CODE tags.

Reply With Quote
Reply

Viewing: Dev Shed ForumsSystem AdministrationApache Development > How to run apache module before the php module?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap