doutui7955 2015-11-14 13:45
浏览 57

在服务器上加载网页 - PHP

I have a web page that contains a php script that pulls data from an API and stores it in a database. My problem is that the script takes 10 minutes to run and stops if the user navigates away from the page on which it's loading - not ideal!

To solve this I'd like to run/load this page on my server as a background job so that a users can still navigate the site without the site or script hanging.

I've had a look at shell_exec but cant seem to make that work:

<?php
shell_exec("/usr/bin/php http://example.com/data_base_update.php &");
?>

Does anyone know how to trigger a URL on the server, for example http://example.com/data_base_update.php without using a cron job?

Thanks,

Matt

  • 写回答

2条回答 默认 最新

  • dqudtskm49788 2015-11-14 14:02
    关注

    I am not a PHP expert, however your approach for achieving the goal seems bit wrong.

    My recommendation is whenever the URL is hit, start an async task in the background and return the control immediately. Writing async task in PHP does not look simple, however this theard will help. You can also use PThreads.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度