如何停止php函数的执行?
我有一个 php 脚本(称之为 file1),我已将其安排为 cronjob...该脚本调用另一个 php 文件(file2)中的另一个 php 函数......现在发生的情况是由于某些未知原因,这个函数执行两次(即文件1从文件2调用函数)......
任何人都可以告诉可能是什么原因以及什么可以是解决方案......我认为它是某种与操作系统/线程相关的问题,但是你的专家的意见更有价值...
谢谢
i've a php script(call it file1) which i've scheduled as a cronjob...this script calls another php function in another php file(file2)......now what happens is for some unknown reason, this function executes twice (i.e. file1 calls function from file2)......
can anyone tell what could be the reason and what can be the solution...what i think is its some sort of OS/threads related issue but your expert opinion is more valueable...
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果没有看到你的代码(也可能还有 cron 配置),很难说太多,但我的猜测是,要么你在程序中调用该函数两次而没有意识到,要么你的 cron 配置导致了该程序运行两次
您可以尝试在两段 PHP 代码的不同位置使用 getmypid() 函数输出 PID;这将帮助您确定哪个进程调用了该函数的每个调用,并且可能会帮助您了解实际发生的上述场景(或完全不同的情况)。
Hard to be able to tell much without seeing your code (and possibly the cron config as well), but my guess would be that either you're calling the function twice in your program without realising it or else your cron config is causing the program to be run twice
You could try outputting the PID using the
getmypid()
function at various places in your two bits of PHP code; this will help you determine which process invoked each call to the function, and will probably help you see which of the above scenarios (or something entirely different) is actually happening.