PECL_HTTP已安装,但不起作用

时间:2016-11-09 04:03:42

标签: php pear pecl lampp

我已经安装了pecl_http,但是当我尝试使用它时,我收到错误:

  

致命错误:未捕获错误:在/opt/lampp/htdocs/tes_http.php:3中调用未定义函数http_get()堆栈跟踪:#opt {lamp}抛出/opt/lampp/htdocs/tes_http.php on第3行

这是我的php.ini配置:

extension="propro.so"
extension="http.so"
extension="raphf.so"
[PHP]

;;;;;;;;;;;;;;;;;;;

请帮我弄清楚该功能无法使用的原因。

1 个答案:

答案 0 :(得分:5)

当前版本的http扩展程序( package名称pecl_http)并未提供http_get()功能。此功能已在2.0.0版(1.7.6版之后)中删除。您可以通过在终端中运行以下命令来查看它:

git clone https://github.com/m6w6/ext-http.git
cd ext-http
git diff RELEASE_1_7_6 RELEASE_2_0_0

虽然在changelog中没有明确提及,但在第二个版本中,过程样式完全被OOP样式替换。

documentation on PHP's official site已过时。 Extension的作者在his own site上托管了新版本。我不会责怪他,因为PECL site上的文档链接指向了正确的位置。毫无疑问,他应该从php.net/manual删除旧文档,或者至少更新它。

执行HTTP GET请求的新方法意味着使用http\Client\Request class:

$request = new http\Client\Request("GET",
  "http://example.com",
  ["User-Agent"=>"MyAgent/0.1"]
);
$request->setOptions(["timeout" => 1]);

$client = new http\Client;
$client->enqueue($request)->send();

$response = $client->getResponse();

关于设置

您应该在<{em} http.so之前加载 ; obligatory deps extension = raphf.so extension = propro.so ; if shared deps were enabled extension = hash.so extension = iconv.so extension = json.so ; finally load pecl/http extension = http.so 之前的依赖项:<{3}}:

/// <summary>
/// Enables the efficient, dynamic composition of query predicates.
/// </summary>
public static class PredicateBuilder
{
    /// <summary>
    /// Creates a predicate that evaluates to true.
    /// </summary>
    public static Expression<Func<T, bool>> True<T>() { return param => true; }

    /// <summary>
    /// Creates a predicate that evaluates to false.
    /// </summary>
    public static Expression<Func<T, bool>> False<T>() { return param => false; }

    /// <summary>
    /// Creates a predicate expression from the specified lambda expression.
    /// </summary>
    public static Expression<Func<T, bool>> Create<T>(Expression<Func<T, bool>> predicate) { return predicate; }

    /// <summary>
    /// Combines the first predicate with the second using the logical "and".
    /// </summary>
    public static Expression<Func<T, bool>> AND<T>(this Expression<Func<T, bool>> first, Expression<Func<T, bool>> second)
    {
        return first.Compose(second, Expression.AndAlso);
    }

    /// <summary>
    /// Combines the first predicate with the second using the logical "or".
    /// </summary>
    public static Expression<Func<T, bool>> OR<T>(this Expression<Func<T, bool>> first, Expression<Func<T, bool>> second)
    {
        return first.Compose(second, Expression.OrElse);
    }

    /// <summary>
    /// Negates the predicate.
    /// </summary>
    public static Expression<Func<T, bool>> Not<T>(this Expression<Func<T, bool>> expression)
    {
        var negated = Expression.Not(expression.Body);
        return Expression.Lambda<Func<T, bool>>(negated, expression.Parameters);
    }

    /// <summary>
    /// Combines the first expression with the second using the specified merge function.
    /// </summary>
    static Expression<T> Compose<T>(this Expression<T> first, Expression<T> second, Func<Expression, Expression, Expression> merge)
    {
        // zip parameters (map from parameters of second to parameters of first)
        var map = first.Parameters
            .Select((f, i) => new { f, s = second.Parameters[i] })
            .ToDictionary(p => p.s, p => p.f);

        // replace parameters in the second lambda expression with the parameters in the first
        var secondBody = ParameterRebinder.ReplaceParameters(map, second.Body);

        // create a merged lambda expression with parameters from the first expression
        return Expression.Lambda<T>(merge(first.Body, secondBody), first.Parameters);
    }

    class ParameterRebinder : ExpressionVisitor
    {
        readonly Dictionary<ParameterExpression, ParameterExpression> map;

        ParameterRebinder(Dictionary<ParameterExpression, ParameterExpression> map)
        {
            this.map = map ?? new Dictionary<ParameterExpression, ParameterExpression>();
        }

        public static Expression ReplaceParameters(Dictionary<ParameterExpression, ParameterExpression> map, Expression exp)
        {
            return new ParameterRebinder(map).Visit(exp);
        }

        protected override Expression VisitParameter(ParameterExpression p)
        {
            ParameterExpression replacement;

            if (map.TryGetValue(p, out replacement))
            {
                p = replacement;
            }

            return base.VisitParameter(p);
        }
    }
}