Вопрос

I'm aware this can appear to be a very silly question for most of the IT crowd, but I'm new at designing this kind of architecture (only developed in PHP before).

I'm building an application that makes use of a specific OS function. The end user is going to call a PHP script that in turn needs to call a C program. The latter will call OS API and return the results in the form of strings and a file pointer to the PHP script.

Now, I know I have the option to deploy this C program either as a command line tool or a daemon. Why should I choose one instead of the other?

Это было полезно?

Решение 4

Deamon is a process that always run in background in memory. Deamons are used for
recurrent task execution like monitoring processes or data changes or etc. And command line-tool is a program that could be executed only when you needed. So my solution would be to use cmd tool because:

  1. Deamon always run in memory
  2. If the deamon crashes who will be responsible for restarting it?
  3. You have to implement simultaneous request control

So my opinioin is cmd tool. But if you want some kind of deamon behave there is other option. If you need to run php script or cmd tool repetitively use cron under linux or scheduler under windows

Другие советы

A daemon is a program that starts when the computer starts, and keeps running until the computer shuts down. Server programs like the Apache web server is a daemon, for example.

If you just want a program that does a quick system call and returns the result, there is really no reason to have it as a daemon, unless it's supposed to be used as a server program where multiple "clients" can connect and request this system call.

A daemon is typically a background process, so if you want your program to sit in the background and monitor something (e.g. report log file size increase every 5 minutes the last hour) and then report the results when someone watches a web page, a deamon is the correct choice.

If you instead want to do something that can be done immediately (e.g. report current log file size), a command line tool is easier to create and maintain.

As a side note: You may also write a php C++ extension to call OS specific functions.

A tool does action X. (E.g. convert a file), if it's quick and fast there should be no need to write a daemon. Daemons often come into play when you need synchronous writing/reading, or queueing.

An easy and popular way to write daemons nowadays to wrap command line commands is nodejs, see for example here: http://blog.nodejitsu.com/keep-a-nodejs-server-up-with-forever

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top