12

my server is in a LAN and is connected to internet through a Proxy Server. my PHP application (Drupal), should be able to check for updates through PHP codes. how can i set Proxy Settings for PHP so that it function properly?

Note: i know that i can set proxy settings in curl or something else. but the case is that the code is not mine and i don't wanna change it. i just want to make PHP always connect to internet through a specific proxy settings.

Alexar
  • 256
  • 1
  • 3
  • 13

5 Answers5

7

This feature is not implementet in php, but (was) in discussion:
http://bugs.php.net/bug.php?id=29280

if you have php >= 5.3 you could use auto_prepend ini setting to include a script that uses stream_context_set_default() to set a default proxy. but this will only set a proxy for the parts of php which use the default context, didnt test it but i think curl fore example doesent.

Florian F
  • 307
  • 3
  • 13
  • It should work on curl too, at least in the source code there's the logic for it: [link](http://svn.php.net/viewvc/php/php-src/trunk/ext/curl/streams.c?view=markup) – aseques Feb 14 '12 at 16:07
  • There is a working exemple in [stackoverflow](http://stackoverflow.com/questions/1336262/file-get-contents-behind-a-proxy) that use stream_context_create instead of context_set_default, but it will work if you change it. – aseques Feb 15 '12 at 07:31
1

Have you tried setting environment variables?

http_proxy=http://proxy.example.com:8080

RedGrittyBrick
  • 3,832
  • 1
  • 17
  • 23
0

I don't know your distribution, but in SUSE you can edit the file /etc/sysconfig/proxy and enter one or multiple proxy servers for system wide usage.

Here is an example:

## Path:        Network/Proxy
## Description:
## Type:        yesno
## Default:     no
## Config:      kde,profiles
#
# Enable a generation of the proxy settings to the profile.
# This setting allows to turn the proxy on and off while
# preserving the particular proxy setup.
#
PROXY_ENABLED="yes"

## Type:        string
## Default:     ""
#
# Some programs (e.g. lynx, arena and wget) support proxies, if set in
# the environment.  SuSEconfig can add these environment variables to
# /etc/SuSEconfig/* (sourced by /etc/profile etc.) -
# See http://portal.suse.com/sdb/en/1998/01/lynx_proxy.html for more details.
# Example: HTTP_PROXY="http://proxy.provider.de:3128/"
HTTP_PROXY="http://your.proxy.here:3128"

## Type:        string
## Default:     ""
#
# Some programs (e.g. lynx, arena and wget) support proxies, if set in
# the environment.  SuSEconfig can add these environment variables to
# /etc/SuSEconfig/* (sourced by /etc/profile etc.) -
# this setting is for https connections
HTTPS_PROXY="http://your.proxy.here:3128"

## Type:        string
## Default:     ""
#
# Example: FTP_PROXY="http://proxy.provider.de:3128/"
#
FTP_PROXY="http://your.proxy.here:3128"

## Type:        string
## Default:     ""
#
# Example: GOPHER_PROXY="http://proxy.provider.de:3128/"
#
GOPHER_PROXY=""

## Type:        string(localhost)
## Default:     localhost
#
# Example: NO_PROXY="www.me.de, do.main, localhost"
#
NO_PROXY="localhost, 127.0.0.1"
Christian
  • 4,703
  • 2
  • 24
  • 27
  • thanks. i use Ubuntu and i have currently set proxy for system-wide usage. but it just do not work. – Alexar Oct 15 '10 at 09:38
0

If your server is connected in such a way that it can only send http requests through the proxy, then you shouldn't need to make any changes. However, you will want to make sure you have a way of verifying that your http requests are made through the proxy.

Also note - your proxy may not be handling all requests - just http/https. Traffic might be passing through the proxy, but if the proxy isn't configured to handle those in anyway, they may pass through without much trace.

If you think this may be happening, I'd tighten up the firewall on the PHP server so that it can only send specified kinds of traffic to specified locations. You should then be able to see what is failing and take appropriate action.

dunxd
  • 9,632
  • 22
  • 81
  • 118
0

do you need still info?

anyway - for the record: a long outstanding issue this is in drupal http://drupal.org/node/7881 - really strange. - and there's much more

I patched my core code, but one has to track the patches changes on upgrading and it's not nice.

If there's a way to make php use systemwide proxy , i have no idea, searching for it was tedious.

greets

groovehunter
  • 243
  • 2
  • 7