在PHP开发中,有时候需要在内部网中进行开发。对于数据收集项目,有时候服务器需要连接Internet网络来获取Internet网络上的信息。但是,如果公司是通过防火墙上网,一般的file_get_content函数就不行了。当然,通过一些socket操作,直接向proxy写http请求也是可以的,但是比较麻烦。本文讨论用CURL库的简单代理实现。
1. CURL库的安装
查Google可以发现很多关于CURL库安装的文档,但实际上,一般的Linux Installation都包含了CURL库。我们可以通过<? phpinfo() ?>检查php编译参数来获取是否安装CURL库的信息。
如下所示:
./configure' '--host=i386-redhat-linux' '--build=i386-redhat-linux' '--target=i386-redhat-linux-gnu' '--program-prefix=' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib' '--libexecdir=/usr/libexec' '--localstatedir=/var' '--sharedstatedir=/usr/com' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--cache-file=../config.cache' '--with-config-file-path=/etc' '--with-config-file-scan-dir=/etc/php.d' '--enable-force-cgi-redirect' '--disable-debug' '--enable-pic' '--disable-rpath' '--enable-inline-optimization' '--with-bz2' '--wit
使用PHP CURL库通过代理服务器连接外部网络
最新推荐文章于 2024-04-19 16:19:45 发布
本文介绍了如何在PHP开发中,当服务器需要通过代理服务器连接到Internet时,使用CURL库进行设置和操作。内容包括CURL库的安装检查,以及示例代码展示如何设置代理、用户代理和超时等参数,从而实现通过代理服务器获取网页内容。

最低0.47元/天 解锁文章
344

被折叠的 条评论
为什么被折叠?



