它是明智的使用PHP的守护进程? [英] Is it wise to use PHP for a daemon?

查看:110
本文介绍了它是明智的使用PHP的守护进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望创建一个后台进程,我已经被告知这些通常用C或诸如此类的东西。我最近发现PHP可以用来创建一个后台进程,我希望能得到一些建议,如果我应该这样使用PHP。

I wish to create a background process and I have been told these are usually written in C or something of that sort. I have recently found out PHP can be used to create a daemon and I was hoping to get some advice if I should make use of PHP in this way.

下面是我要求的守护程序。

Here are my requirements for a daemon.


  • 连续检查,如果某行已
    添加到MySQL数据库表

  • 运行FFmpeg的上是什么命令
    从数据库中检索

  • 插入输出转换成MySQL表

我不知道还有什么我可以提供帮助做出这个决定。我想补充,我没有做过℃。只有Java和PHP和基本的bash脚本编程。

I am not sure what else I can offer to help make this decision. Just to add, I have not done C before. Only Java and PHP and basic bash scripting.

这是否甚至使太大的性能差异是什么?

Does it even make that much of a performance difference?

请允许我的无知,我学习! :)

Please allow for my ignorance, I am learning! :)

感谢所有

推荐答案

正如其他人所指出的,PHP的各种版本与他们的垃圾收集器的问题。当然,如果你知道你的版本没有这样的问题,可以消除这一问题。问题的关键是,您不要知(肯定的),直到你写的守护进程,并通过Valgrind的运行它,看看是否安装了PHP泄漏或没有任何给定的机器上。因此,对那只手,你可以把它写只是为了发现什么Zend公司认为是固定的可能仍然是越野车,或者你正在处理一个稍旧版本的PHP或者一些扩展。恶心。

As others have noted, various versions of PHP have issues with their garbage collectors. Of course, if you know that your version does not have such issues, you eliminate that problem. The point is, you don't know (for sure) until you write the daemon and run it through valgrind to see if the installed PHP leaks or not on any given machine. So on that hand, you may write it just to discover that what Zend thinks is fixed might still be buggy, or you are dealing with a slightly older version of PHP or some extension. Icky.

的另一个问题是有些手推车信号。根据我的经验,信号处理并不总是正确使用PHP进入,特别是当信号进行排队,而不是合并。这可能不是你的问题,即,如果你只需要处理SIGINT / SIGUSR1 / SIGUSR2 / SIGHUP。

The other problem is somewhat buggy signals. In my experience, signal handlers are not always entered correctly with PHP, especially when the signal is queued instead of merged. That may not be an issue for you, i.e. if you just need to handle SIGINT/SIGUSR1/SIGUSR2/SIGHUP.

所以,我建议:

如果守护程序很简单,继续使用PHP。如果它看起来像它会变得相当复杂,或分配大量内存,你可能会考虑在PHP原型后用C写它。

If the daemon is simple, go ahead and use PHP. If it looks like its going to get rather complex, or allocate lots of memory, you might consider writing it in C after prototyping it in PHP.

我是pretty难改Ç人。不过,我认为没有错,制定出一些快速使用PHP(超出我解释的情况下)。我也认为没有错用PHP为原型的东西,可能会或可能不会在后面C.改写比如,处理数据库的东西是要简单得多,如果你使用PHP,与管理使用其他接口,在C回调所以在该实例,对于一次性,你一定会得到它更快地完成。

I am a pretty die hard C person. However, I see nothing wrong with hammering out something quick using PHP (beyond the cases that I explained). I also see nothing wrong with using PHP to prototype something that may or may not be later rewritten in C. For instance, handling database stuff is going to be much simpler if you use PHP, versus managing callbacks using other interfaces in C. So in that instance, for a 'one off', you will surely get it done much faster.

这篇关于它是明智的使用PHP的守护进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆