PHP 与SOAP消息代理有什么用?

发布于 2024-09-26 11:41:59 字数 830 浏览 4 评论 0原文

我正在研究一种解决方案,使大型数据库中的某些数据可用于远程网站。我的第一个想法是简单地编写一些肥皂网络服务来从数据库中获取某些数据。这可以用几行完成,例如像这样,对于 Zend_Soap_Server 的用户:

class MyClass 
{
    public function getlastname($id) 
    {
        $dbh = new PDO("oci:dbname=bigdb", "theuser", "thepass");

        $stmt = $dbh->prepare("select lastname from person where id  = :id"); 

        if ($stmt->execute(array(':id',$id))) 
        {
         $row = $stmt->fetch();
         return $row['lastname'];
        }
    }
}

$server = new Zend_Soap_Server(null, $options);
$server->setClass('MyClass');
$server->setObject(new MyClass());

$server->handle();

现在有人告诉我也看看消息代理/队列。我一直在研究一些软件,如 apache activeMQ、stomp 和 zend_queue,但我并没有真正清楚地了解它们应该用于什么以及它们在这个项目中是否有用。

我确实知道我的实现可能有一些缺点,例如当数据库没有快速响应时网站反应迟缓,当网站收到大量请求时数据库负载很高,消息代理是否能够防止此类复杂情况?

I'm working on a solution to make certain data from a large database available to a remote website. My first thought was to simply cook up some soap web services to fetch certain data from the database. This could be done in just a few line, for instance like this, with the user of Zend_Soap_Server:

class MyClass 
{
    public function getlastname($id) 
    {
        $dbh = new PDO("oci:dbname=bigdb", "theuser", "thepass");

        $stmt = $dbh->prepare("select lastname from person where id  = :id"); 

        if ($stmt->execute(array(':id',$id))) 
        {
         $row = $stmt->fetch();
         return $row['lastname'];
        }
    }
}

$server = new Zend_Soap_Server(null, $options);
$server->setClass('MyClass');
$server->setObject(new MyClass());

$server->handle();

Now someone told me to also have a look at message brokers / queues. I've been taking a look at some software like apache activeMQ, stomp and zend_queue but I didn't really get a clear view what they should be used for and weather they would be useful in this project.

I do understand that my implementation could have some drawbacks, like a sluggish website when the database is not responding quickly and a high load on the database when there are coming lots of requests from the website, would a message broker be able to prevent such complications?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

长安忆 2024-10-03 11:41:59

消息代理的作用是检查请求并将它们分派到正确的服务或从缓存返回响应。

如果您预计会有大量流量,您可能应该考虑使用消息代理。

问候,
阿林

The role of a message broker is to check the requests and dispatch them to the right service or return a response from a cache.

If you are expecting large traffic you probably should consider using a message broker.

Regards,
Alin

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文