简体   繁体   English

在两个PHP脚本之间发送数据

[英]Send data between two PHP scripts

I want to have a PHP script send a XML formatted string to another PHP script that resides on a different server in a different part of town. 我希望有一个PHP scriptXML格式的字符串发送到另一个PHP script ,该PHP script驻留在城镇的不同部分的不同服务器上。

Is there any nice, clean way of doing this? 这样做有什么好的,干净的方式吗?

(PHP5 and all the latest software available)

检查cURL以在页面之间发布数据。

If it were me, I would just POST the xml data to the other script. 如果是我,我只是将xml数据发布到另一个脚本。 You could use a socket from PHP, or use CURL. 您可以使用PHP中的套接字,或使用CURL。 I think that's the cleanest solution, although SOAP is also viable if you don't mind the overhead of the SOAP request, as well as using a library. 我认为这是最干净的解决方案,尽管如果你不介意SOAP请求的开销以及使用库,SOAP也是可行的。

I strongly suggest rolling your own RESTful API and avoiding the complexity of SOAP altogether. 我强烈建议您使用自己的RESTful API并完全避免SOAP的复杂性。 All you need is the curl extension to handle the HTTP request/response, and simple_xml to build/process the XML. 您只需要处理HTTP请求/响应的curl扩展,以及构建/处理XML的simple_xml。 If your data is in a reasonable format, it should be easy for you to push it into an XML string and submit it as a POST to the other server. 如果您的数据格式合理,则应该很容易将其推送到XML字符串并将其作为POST提交给其他服务器。 That server will respond to the request by reading the XML string from the POST var back into an object, and voila! 该服务器将通过将POST var中的XML字符串读回对象来响应请求,瞧! It shouldn't take you all day to whip this out. 它不应该花一整天时间把它扯出来。

您可以使用卷曲 (复杂的API),将HTTP扩展(清洁剂),或者如果你需要做更多的复杂的东西,你甚至可以使用脚本化浏览器SimpleTest的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM