如何从我的PHP应用程序安全地创建Cron作业?

如何从我的PHP应用程序安全地创建Cron作业?

问题描述:

I am building a web app (using PHP) which needs to offer the end user the functionality to receive an update every x hours, between a range of dates. I know you can create a cron job using "shell". However, I have disabled shell in php.ini to secure my server, in the event of any malicious code finding its way on to my server. Is there a way to securely create a cron job from my app without resorting to using system commands?

Edit

In response to Halayem's comment for further clarification. A registered user in my system may set up a repeating task in my app that will send an SMS message to their mobile number every X Hours where X is a user defined time. I wish to build a secure way of implementing a cron job to automatically send the message every X Hours when the user creates the task.

我正在构建一个Web应用程序(使用PHP),它需要为最终用户提供每次接收更新的功能 x小时,在一系列日期之间。 我知道你可以使用“shell”创建一个cron作业。 但是,我已经在php.ini中禁用了shell来保护我的服务器,以防任何恶意代码进入我的服务器。 有没有办法从我的应用程序安全地创建一个cron作业,而无需使用系统命令? p>

编辑 strong> p>

回应哈拉姆的评论进一步澄清。 我系统中的注册用户可以在我的应用程序中设置重复任务,该任务将每X小时向其移动号码发送SMS消息,其中X是用户定义的时间。 我希望构建一种实现cron作业的安全方法,以便在用户创建任务时每隔X小时自动发送消息。 p> div>

You don't ever dynamically create new cron jobs from code, that's madness. What you do is you set up one cron job explicitly which checks every so often if there's something to do, and you keep a database of tasks that the cron job should do.

Simple example: if there's an option for your customers to receive a mail every hour, then you set up a cron job which checks your database every hour for which customers opted into receiving a mail and then sends those mails.