简体   繁体   English

Cron作业的PHP文件自动随机运行

[英]PHP file for Cron job runs automatically randomly

I've a PHP based app. 我有一个基于PHP的应用程序。 We've to run a PHP file (say xyz.php) once daily to send emails. 我们每天要运行一个PHP文件(比如xyz.php)来发送电子邮件。 We use Cron job in cPanel to run that file everyday in the morning. 我们在cPanel中使用Cron作业每天早上运行该文件。 I've setup my email as cron email so that I get notified every time the cron job is executed. 我已将我的电子邮件设置为cron电子邮件,以便每次执行cron作业时都会收到通知。 It runs perfectly in the morning - sends the data which is required correctly and I also get notified via email every morning that cron job executed successfully. 它在早上运行完美 - 发送正确所需的数据,我每天早上都会通过电子邮件通知cron作业成功执行。

That PHP file's URL (abc.com/xyz.php) if entered in browser manually will also send emails. 如果手动在浏览器中输入该PHP文件的URL(abc.com/xyz.php),也会发送电子邮件。

Now coming to the problem part - The email IDs in the PHP file start getting emails at random times and sometimes 30-40 emails a day. 现在来看问题部分 - PHP文件中的电子邮件ID开始随机收到电子邮件,有时每天收发30-40封电子邮件。 The emails are incomplete and incorrect. 电子邮件不完整且不正确。 I don't get any notification email that cron job has executed. 我没有收到任何cron作业已执行的通知电子邮件。 So, my guess is the PHP file is accessed by something which triggers the emails. 所以,我的猜测是PHP文件被触发电子邮件的东西访问。 I've checked access logs in the cPanel but there's nothing in there. 我已经检查了cPanel中的访问日志,但那里什么也没有。

The app is hosted on Hostgator, if that helps. 该应用程序托管在Hostgator上,如果有帮助的话。

Please help. 请帮忙。 Thanks! 谢谢!

这可能发生在你将abc.com/xyz.php include在其他一些php文件上时,这些文件在通过浏览器调用php页面并且某些部分表单被执行时执行,你也不会得到这种类型的邮件通知exectutions

Some exmplanations: 一些例外:

  • You may have included the file in some code, 您可能已将该文件包含在某些代码中,
  • Someone is accessing the file (but you outed that) 有人正在访问该文件(但你已经开始了)
  • There may be another cron job defined (it may happend if for some reason two jobs were created or someone created it by other panels, by hand with different times) - like for testing. 可能会定义另一个cron作业(如果出于某种原因,可能会发生两个作业,或者有人通过其他面板,不同时间手动创建它) - 就像测试一样。
  • Someone may execute it manually 有人可以手动执行它

    1. you you must find out yourself. 你必须找到自己。
    2. block it by password or totally with .htaccess 用密码或完全用.htaccess阻止它
    3. check your cron settings (also for each user crontable) 检查你的cron设置(也为每个用户crontable)
    4. check logs 检查日志

Also - WRITE some code into you php file that will log HOW and WHEN it was executed - that will allow you to further test what is happening. 另外 - 将一些代码写入您的php文件中,该文件将记录HOW以及何时执行 - 这将允许您进一步测试正在发生的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM