3

Could someone explain me in two words, what is daemon and what use of them in php?

I, know that this is a process, which is runing all the time. But i can't understand what use of it in php app?

Can someone please give examples of use? Can i use daemon to lessen memory usage of my app?

As i understand, daemon can hold data and give it on request, so basically i can store most usable data there, to avoid getting it from mysql for each visitor?

Or i'm totally wrong? :)

Thanks ;)

Somebody
  • 9,316
  • 26
  • 94
  • 142
  • 3
    You shouldn't do daemons in PHP if you don't have to. There are much better solutions and languages for this – Pekka Nov 07 '10 at 14:07
  • @Pekka: is there any particular reason? I'm not much of a PHP dev so are there features of the runtime that make it particular unsuitable for persistent processes? – Joe Nov 07 '10 at 14:12
  • 1
    @Joe its main task is to run short-lived scripts to quickly serve requests, so it's not very strong in garbage collection. Also as noted in the following link, it tends to have issues with interprocess communication. That said, it's not impossible to create a daemon in PHP, though. Good discussion is here: http://stackoverflow.com/questions/646928/is-it-wise-to-use-php-for-a-daemon – Pekka Nov 07 '10 at 14:13
  • I didn't said in php, i said with php. – Somebody Nov 07 '10 at 14:14
  • PHP is good at triggering daemon scripts. Theoretically you can, but it was never intended for use in writing native PHP daemons. – bcosca Nov 07 '10 at 14:15
  • I'm talking about daemon itself, written on another programming language. What use it can give to app written with php, in performance meaning. – Somebody Nov 07 '10 at 14:16

4 Answers4

1

A daemon is a endless running process, which just waits for jobs. A webserver ("http-daemon") waits for requests to handle, a printer daemon waits for something to print (and so on). On Win systems its called "service".

If you can use it for your application in some way highly depends on your application and what you want to do with a daemon. But also I dont recommend PHP for that.

KingCrunch
  • 128,817
  • 21
  • 151
  • 173
0

Could someone explain me in two words, what is daemon and what use of them in php?

cli application or process

I, know that this is a process, which is runing all the time. But i can't understand what use of it in php app?

You can use it to do; job that is not visible to user or from interface, e.g. database stale data cleanup, schedule task that you you wanted to update part or something on db or page in background

Can someone please give examples of use? Can i use daemon to lessen memory usage of my app?

I think drupal or cron had cron script...perhaps checking it would help. Lessen memory? no, memory optimization is always on the application design or script coded.

As i understand, daemon can hold data and give it on request, so basically i can store most usable data there, to avoid getting it from mysql for each visitor?

No, a daemon is a script however you can create a JSON or XML data file that the daemon script can process.

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
SlamDunk
  • 44
  • 1
0

Please see this answer regarding the use of PHP for a daemon. There are times when you might want to fork a child process in PHP, perhaps to execute some query while the parent does other work and then inform the parent that the job as a whole can be completed.

I would not, however use PHP to set up a socket server or similar, nor would I use PHP in any other instance where execution was measured in units greater than seconds.

I don't want to discourage you from exploring and experimenting, just caution you against putting too much trust in an implementation that exceeds the capabilities of the language.

Community
  • 1
  • 1
Tim Post
  • 33,371
  • 15
  • 110
  • 174
0

Because a daemon is just a process that runs in an infinite loop, whether or not a daemon can be helpful for your particular app is entirely up to the daemon and the requirements of your app.

MySQL is itself run as a daemon, but a typical way of decreasing the number of calls to MySQL is to cache their output in Memcached (which not surprisingly also runs as a daemon). So the advantage of using Memcached isn't that it's a daemon, it's that it's a daemon more geared to a specific task (caching objects) than MySQLd (providing a SQL-queryable database).

If your app repeatedly needs to make the same SQL queries, then it's definitely worth considering using Memcache or another caching layer (which, yes, will most likely be provided by a daemon) in between the app and MySQL.

Ben Regenspan
  • 10,058
  • 2
  • 33
  • 44