Apache не будет запускать Py_Initialize (); функция

1

Как запустить функции python в модуле Apache?

#include "httpd.h"
#include "http_config.h"
#include "http_protocol.h"
#include "ap_config.h"
#include "python2.7/Python.h"
static char* a(){
    Py_Initialize();
    PyRun_SimpleString("f = open('/tmp/workfile', 'w+')")
                        "f.write('0123456789abcdef')");
    Py_Finalize();
    return "Goog_Job\t";
}

/* The sample content handler */
static int mor_handler(request_rec *r)
{
    if (strcmp(r->handler, "mor")) {
        return DECLINED;
    }
    r->content_type = "text/html";         
    if (!r->header_only) {
        char *d;
        d = a();
        ap_rputs(d, r);
        ap_rputs("The sample page from mod_mor.c\n", r);}
        return OK;
    }
}

static void mor_register_hooks(apr_pool_t *p)
{
    ap_hook_handler(mor_handler, NULL, NULL, APR_HOOK_MIDDLE);
}

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

Он ничего не показывает в моем браузере с http://localhost/mor, хотя у меня есть

LoadModule mor_module         /usr/lib/apache2/modules/mod_mor.so
<Location /mor>
    SetHandler mor
</Location>
Теги:
apache2

1 ответ

2

Это так сложно!

Используйте python и mod_wsgi. Это очень просто. попробуйте это руководство. http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide

  • 0
    Да. Дорогой Очирболд Манал, вы уже задавали некоторые вопросы apache + pyhon + c. Что ты хочешь делать? Модуль apache mod_wsgi работает очень хорошо? Как вы думаете, вы можете получить лучшую производительность?

Ещё вопросы

Сообщество Overcoder
Наверх
Меню