在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/sha
使用PHP CURL库通过代理服务器连接外部网络
最新推荐文章于 2023-05-31 09:08:13 发布