0

我需要设置CURLOPT_TCP_NODELAYCURL 选项,但问题是我不知道如何使用 Sf2 的服务容器来做到这一点。

这是Guzzle现在注入的方法:

services:
    user.user_manager:
        class: Foo\UserBundle\Model\UserManager
        arguments:
            - @guzzle.client

但我也需要补充CURLOPT_TCP_NODELAY

普通的 PHP 示例:

$guzzle = new \Guzzle\Http\Client(null, array(
    'curl.options' => array(
        'CURLOPT_TCP_NODELAY' => 1
)));
4

1 回答 1

5

您可以创建自定义 Guzzle 客户端并将其声明为服务:

<?php

namespace You\ProjectBundle\Guzzle;

class MyGuzzleClient extends \Guzzle\Http\Client
{
    public function __construct()
    {
        parent::__construct(null, array(
            'curl.options' => array('CURLOPT_TCP_NODELAY' => 1)
        ));
    }
}

然后将其声明为服务:

services:
    my_guzzle.client:
        class: You\ProjectBundle\Guzzle\MyGuzzleClient

最后,按如下方式使用:

services:
    user.user_manager:
        class: Foo\UserBundle\Model\UserManager
        arguments:
            - @my_guzzle.client
于 2014-06-05T09:13:59.847 回答