PHP提早发送SOAP响应? [英] PHP send SOAP response early?

查看:81
本文介绍了PHP提早发送SOAP响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我一直在处理的老问题,但仍然没有解决方案,因此请尝试一种新方法.

Well this is an old issue I've been dealing with and still no solution, so trying a new approach.

如何提前发送SOAP响应(在脚本执行结束之前)?

How can I send th SOAP response early (Before script execution ends)?

这些问题是由于在30秒内未发送ACK文件而导致的,原因是该过程需要更长的时间才能完成分配的时间.

These issues are cause when the ACK file is not sent before 30 seconds as the process takes longer to complete then the allotted time.

flush()不起作用,出现此错误:

flush() not working, get this error:

org.xml.sax.SAXParseException:XML文档结构必须在同一实体内开始和结束.

org.xml.sax.SAXParseException: XML document structures must start and end within the same entity.

没有flush()我得到了

without the flush() I get this

org.xml.sax.SAXParseException:文件的结尾过早.

org.xml.sax.SAXParseException: Premature end of file.

脚本过程可能需要180秒才能完成,并且服务器等待响应仅等待大约30秒后才超时(这是造成上述错误的原因).

The script process can takeover 180 seconds to complete and the server waiting for the response only wait for about 30 seconds before timing out (Which cause the above error).

关于如何解决此问题的任何想法?

any thoughts as to how I can fix this?

这是一些代码:这就是我如何接受和发送即将到来的SOAP请求的ACK文件

Here is some of the code: This is how I accept and send the ACK file for the imcoming SOAP request

$data = 'php://input';
$content = file_get_contents($data);

if($content) {
    respond('true');
} else {
    respond('false');
}

响应功能

function respond($tf) {
    $ACK = <<<ACK
<?xml version = "1.0" encoding = "utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Body>
        <notifications xmlns="http://soap.sforce.com/2005/09/outbound">
            <Ack>$tf</Ack>
        </notifications>
    </soapenv:Body>
</soapenv:Envelope>
ACK;

    print trim($ACK); 
}

PHP使用单线程处理方法,直到线程完成处理后,才会发回ACK文件.有什么方法可以在提交ACK之后关闭套接字并继续进行处理,这样我就不会在发送服务器上收到这些超时问题了?

PHP uses a single thread processing approach and will not send back the ACK file until the thread has completed it's processing. Is there some way to close the socket after the ACK submission and continue the processing so I don't get these timeout issues on the sending server?

推荐答案

据我所知,我们无法对30秒的限制做任何事情,并且在脚本完成之前不会刷新输出.您可以尝试将处理逻辑分为两部分吗?

As far as I know we can't do anything about the 30 second limit and the output won't be flushed before the script finishes. Can you try splitting your processing logic into 2 pieces?

  1. 侦听器"脚本,用于接收消息,记录要完成的作业并立即发送ACK,然后退出.
  2. 您实际进行的处理可能会花费更长的时间.

要完成的工作"可能是新产生的过程(请查看

The "job to be done" could be a newly spawned process (check out the comments for the pcntl_fork() function but they don't look too promising to me) or some way to store the data in file or database and periodically process it with another script, for example scheduled to run every 5 minutes?

如果60秒钟能以某种方式拯救您,则可以将出站消息重写为Apex的标注.基本上,您然后编写自己的SOAP信封并将其发送到任何http地址.您可以将其触发.有关此方法的限制,请参见此处.

If 60 seconds would somehow save you, you could rewrite your outbound message into a callout from Apex. Basically you then write your own SOAP envelope and send it to any http address. You could put it in a trigger. See here for limitations of this approach though.

其他咆哮:

  1. 我认为您的ACK不会真正影响销售人员.出站邮件只是通知.您是否在应用程序的其他地方依赖Ack = true/false?如果不是,则盲目发送ack = true&的侦听器安排工作可能真的是要走的路;)
  2. 从其他问题中我了解到,您基本上只需要将更新存储在您这边.您意识到不应将OM用于审计目的,对吗? (链接,搜索审核").
  3. 让PHP成为积极的一面会更简单吗?使它查询Salesforce的[选择ID,名称,来​​自帐户的名称,LastModifiedDate>:lastTimeYouQueried]?这样,您就可以花费所有时间来处理结果:)
  1. I don't think your ACK really "matters" to salesforce. Outbound messages are just notifications. Do you rely somewhere else in your application on Ack = true/false? If not - listener that blindly sends ack=true & schedules the job might really be the way to go ;)
  2. From the other queston I understood you basically just need to store updates in DB on your side. You realize you shouldn't use OM for audit purposes, right? (Link, search for "audit").
  3. Wouldn't it be simpler to make PHP the active side? make it query Salesforce for [SELECT Id, Name FROM Account WHERE LastModifiedDate > :lastTimeYouQueried]? That way you can take all the time you want to process the results :)

这篇关于PHP提早发送SOAP响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆