in reply to Re^2: CGI Header Breaks on Second AJAX Call
in thread CGI Header Breaks on Second AJAX Call

a utility written using PSGI and Perl where the author lamented having to write additional scripts to ensure the services were running.

Same problem as with almost any setup where webserver and applications run on in different processes. PSGI is perl-specific, FastCGI is not. FastCGI keeps your application running in an isolated process, so crashing the webserver does not kill the application, and crashing the application does not kill the webserver. Getting the application process running is a problem.

You could start it manually. Every time your application crashes.

You could construct something crazy, involving hand-started scripts, cron jobs, and I don't know what else to start the application process.

Or you could make starting your application a problem for the operating system. After all, it is able to start the webserver without manual intervention, so it can do the same to your application. (With daemontools and runit, you simply need a shell script to invoke your application. With systemd, you write an INI-style configuration file to do the same job in a much more complicated way. With a classic init system, you set up a daemon by an init script, or invoke it directly from init. On Windows, you need to set up a service.)

Apache also offers mod_fcgid to manage your FastCGI application process(es) for you, instead of using operating system services. Other webservers might offer similar modules. This has the advantage that you don't need to keep the application process(es) running if there are no requests for them. The disadvantage is that they are not as isolated from the webserver as a process started as an independant daemon started by init, daemontools, runit, or systemd.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
  • Comment on Re^3: CGI Header Breaks on Second AJAX Call

Replies are listed 'Best First'.
Re^4: CGI Header Breaks on Second AJAX Call
by karlgoethebier (Abbot) on Apr 14, 2025 at 09:17 UTC

    ”… something crazy…”

    An alternative might be PM2 - it isn`t only for Node:

    
    karl@rantanplan:~/src/perl$ pm2 status --no-vizion --no-color
    ┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
    │ id │ name               │ mode     │ ↺    │ status    │ cpu      │ memory   │
    ├────┼────────────────────┼──────────┼──────┼───────────┼──────────┼──────────┤
    │ 1  │ gizmo              │ fork     │ 0    │ online    │ 0%       │ 7.9mb    │
    │ 0  │ mredis             │ fork     │ 0    │ online    │ 0%       │ 3.5mb    │
    └────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘
    
    

    The process with id 1 is a Perl daemon.

      The ids don't seem to be Unix process ids, more like an internal array index. Why doesn't it report the true process ID?

      The problem with all of those managing software is complexity and feature creep. A sane /sbin/init running as process 1 fits on a page of A4 paper, without resorting to unreadably small letters: Re^14: CPAN failed install

      And I would prefer to have a tiny init, too stupid to crash. Why? Because if init crashes, you are f***ed. init MUST NOT CRASH. Adding a lot of dependencies adds a lot of ways to crash. init has one job, and it is in its name: It must initialize the system. Keeping it running is the job of other programs. These programs should not crash, but if they do, init will restart them.

      Want to have some fun? Disturb the connection between systemd and dbus. Hope and pray that your data survives that: Re: How not to implement updaters. It is almost like hitting the reset button on a running system, but via SSH.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

        ”…don't seem to be Unix process ids…Why doesn't it report the true process ID?”

        Yes i know, that's a bit of a pity. I don't know why they don't do that either.

        karl@rantanplan:~/src/perl$ ps aux | grep [p]erl karl 773100 0.0 0.0 13740 8056 ? Ss Apr13 0:00 perl /home/karl/src +/perl/soc.pl

        On the whole, I agree with you - but the features are really not bad. Unfortunately, you don't like features 😎🤪 A while ago I experimented a bit with Node and PM2 - the cluster capability impressed me a bit - I have to say. That's the reason I came across this tool.