Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

202
Views
Writing application server daemon with mod_proxy_fcgi and nginx proxy_pass

I start to write a daemon (linux), which listen for requests via mod_proxy_fcgi or nginx proxy_pass. A similar application is php-fpm. My daemon is something like c-fpm, talking with specific other daemons (local unix sockets) to do the work with database handling and producing html output.

I search for examples how to handle the fcgi input from webserver. With google I cannot found, what I look for.

The code snippet after getting the input:

clientHdl = sockserver->accept(sockserver, CPSOCK_KEEPALIVE, nullptr, 0);
if( clientHdl > -1 )
{
    PTStream        stream      = nullptr;
    ssize_t         rdBytes     = -1;
    stream          = CPStreamCreate(pool);
    rdBytes         = sockserver->readToStream(sockserver, clientHdl, stream);
    if(rdBytes > 0 )
    {
        char* ptr = stream->getPointer(stream);
        size_t s  = stream->getSize(stream);
        LOGINFO(("%s: [%s]", prefix, ptr ));

    }
    stream->free(stream);
    shutdown(clientHdl, SHUT_RDWR);
    close( clientHdl );
}

The question is: what to do with ptr? For my start it is very hard to read and understand the source of php-fpm. I would love it, to find a simpler example.

Thank you in advance

Edit: the folowing code opened my eyes:

if(rdBytes > 0 )
{
   char*   ptr     = stream->getPointer(stream);
   size_t  s       = stream->getSize(stream);
   char    z;
   char    pbuf[200];
   size_t  pi      = 0;
   for( size_t i = 0; i < s; i++ )
   {
       z   = ptr[i];
       if( z < 32 )
       {
           static const char h[]="0123456789ABCDEF";
           pbuf[ pi++ ]    = '[';
           pbuf[ pi++ ]    = h[ (z >> 4) & 0xF ];
           pbuf[ pi++ ]    = h[ z & 0xF ];
           pbuf[ pi++ ]    = ']';
       }
       else
       {
           pbuf[ pi++ ]    = z;
       }
       if((pi + 5) > sizeof(pbuf))
       {
           pbuf[pi] = '\0';
           LOGINFO(("%s: %s", prefix, pbuf));
           pi      = 0;
       }
   }
   pbuf[pi] = '\0';
   LOGINFO(("%s: %s", prefix, pbuf));
}

So, now I do not know, if I should delete my question or wait for some interesting information from you.

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!