-1

I am wondering how company like snapchat execute their delete function. If I am about to design a feature like snapchat which the file(images, videos) will be deleted after 24 hours the video have been uploaded by the specific user is to execute sleep in php after 24 hours.

  <?php
    **upload code goes here**
    sleep(24);
    **delete code goes here**/

   ?>

I know this is not the best way to do it. I searched around and found something called cron job which you can execute php code in a scheduled time. But I want to delete the specific file that upload by user after 24 hours not the specific time which when the admin execute the delete. Is there a better way to do this? Thanks

4

1 回答 1

2

绝对不要使用睡眠,因为它会锁定你的 PHP 进程,阻止它做任何其他事情。它不会扩展。

在这种情况下,您不会为要删除的每个文件创建一个 cron 作业。相反,您保留数据的时间戳,然后每 15 分钟左右运行一个 cron 作业并查找早于 24 小时的时间戳。然后删除那些记录/文件。

于 2016-04-28T13:04:21.853 回答