什么是守护进程?它们的实际用途是什么?与php一起使用?

发布于 2024-10-01 09:14:37 字数 247 浏览 5 评论 0原文

有人能用两个词解释一下什么是守护进程以及它们在 php 中的用途吗?

我,知道这是一个过程,一直在运行。 但我不明白它在 php 应用程序中有什么用?

有人可以给出使用示例吗? 我可以使用守护进程来减少应用程序的内存使用量吗?

据我了解,守护进程可以保存数据并根据请求提供数据,所以基本上我可以在那里存储大多数可用的数据,以避免为每个访问者从 mysql 获取它?

或者我完全错了? :)

谢谢 ;)

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 ;)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

倾城°AllureLove 2024-10-08 09:14:37

守护进程是一个无限运行的进程,它只是等待作业。网络服务器(“http-daemon”)等待处理请求,打印机守护程序等待打印内容(等等)。在Win系统上它被称为“服务”。

如果您可以以某种方式将它用于您的应用程序,很大程度上取决于您的应用程序以及您想要使用守护程序执行的操作。但我也不推荐使用 PHP。

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.

ˇ宁静的妩媚 2024-10-08 09:14:37

有人能用两个词解释一下什么是守护进程以及它们在 php 中的用途吗?

CLI 应用程序或进程

我,知道这是一个进程,一直在运行。但我不明白它在 php 应用程序中有什么用?

你可以用它来做;对用户或界面不可见的作业,例如数据库陈旧数据清理、您想要在后台更新数据库或页面上的部分或某些内容的计划任务

有人可以给出使用示例吗?我可以使用守护进程来减少应用程序的内存使用量吗?

我认为 drupal 或 cron 有 cron 脚本...也许检查它会有所帮助。减少记忆力?不,内存优化始终取决于应用程序设计或脚本编码。

据我了解,守护进程可以保存数据并根据请求提供数据,所以基本上我可以在那里存储大多数可用的数据,以避免为每个访问者从 mysql 获取数据?

不,守护程序是一个脚本,但是您可以创建守护程序脚本可以处理的 JSON 或 XML 数据文件。

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.

花伊自在美 2024-10-08 09:14:37

请参阅此答案了解使用 PHP 作为守护进程。有时,您可能希望在 PHP 中分叉一个子进程,也许是在父进程执行其他工作时执行某些查询,然后通知父进程整个作业可以完成。

但是,我不会使用 PHP 来设置套接字服务器或类似服务器,也不会在以大于秒为单位测量执行的任何其他实例中使用 PHP。

我不想阻止您探索和实验,只是警告您不要过于信任超出语言能力的实现。

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.

夜雨飘雪 2024-10-08 09:14:37

因为守护进程只是一个在无限循环中运行的进程,所以守护进程是否对您的特定应用程序有帮助完全取决于守护进程和您的应用程序的要求。

MySQL 本身作为守护进程运行,但减少 MySQL 调用次数的典型方法是将其输出缓存在 Memcached 中(毫不奇怪,Memcached 也作为守护进程运行)。因此,使用 Memcached 的优势不在于它是一个守护进程,而在于它是一个比 MySQLd(提供可 SQL 查询的数据库)更适合特定任务(缓存对象)的守护进程。

如果您的应用程序反复需要进行相同的 SQL 查询,那么绝对值得考虑在应用程序和 MySQL 之间使用 Memcache 或其他缓存层(是的,很可能由守护进程提供)。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文