0

所以我有一个带有 PHP 脚本的服务器,它将被 xml 帖子轰炸。每个 xml 可能有 1 个数据块或几个数据块,发布给我的服务器有大约 10 秒的可变超时,所以我的脚本有大约 10 秒的时间告诉他们的服务器得到了这些东西(http:200/page完成加载),否则他们将重新尝试将系统潜入循环中。我的周转时间需要几乎是即时的,因为必须尽快发送由于此 xml 而发送的电子邮件和电话等。

我曾考虑过执行以下操作:将 xml 转储到 txt 文件中并在数据库中记录日志,因此该文件将始终在 10 秒内响应 xml 海报。然后在后台处理文件。有人在另一个线程中建议这样做:

#!/bin/bash
while [ "true" ]; do
        /path/to/script.php
        sleep 3
done

我的问题是,如果我得到 40 个大型批处理作业和 20 个小型批处理作业,那么在一分钟内我可以运行 30 个 script.php 实例。我想让批处理脚本运行,并在它完成后启动下一个批处理脚本等等,而不会导致内存问题。

那么最好执行以下操作:

处理器.php:

<?php
select next record sort by date desc
grab file, process it
header location to same script
?>

如果没有记录,那么可能睡眠 3,所以页面一直在运行,我有一个 cron 检查它是否处于活动状态,如果出现问题,它可以重新启动。但这会导致男性问题,或者当它的标题定位到自身时它会重置内存?

有什么建议么?

4

1 回答 1

1

听起来不错的计划,怎么样:

接收器.php

//Receive XML
//Option 1: Store in text file (with timestamp in name)
//  or
//Option 2: Store in text file and then store timestamped reference in database
//Respond to caller

processor.php(每 10 秒激活一次或通过 cron 激活)

//Option 1: Check for new XML text files - grab the one with the oldest timestamp
//Option 2: Check database for oldest unprocessed XML - grab the referenced XML file
//Process XML
//Remove XML text file (& any reference in a database)
//Go back to the start of the processor.php script  (while loop or something that checks for unprocessed XML files)
于 2013-04-13T16:29:54.263 回答