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.

0

5 Answers 5

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.

2
  • It should work on curl too, at least in the source code there's the logic for it: link
    – aseques
    Feb 14, 2012 at 16:07
  • There is a working exemple in stackoverflow that use stream_context_create instead of context_set_default, but it will work if you change it.
    – aseques
    Feb 15, 2012 at 7:31
1

Have you tried setting environment variables?

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

7
  • no, should i do this using putenv() or in .htaccess?
    – Alexar
    Oct 15, 2010 at 9:29
  • Neither, Try editing /etc/environment Oct 15, 2010 at 10:50
  • 1
    If /etc/environment doesn't help, I'd edit /etc/apache2/envvars and I'd put in both http_proxy and HTTP_PROXY as different applications have different conventiopns sometimes. Do a full stop and a restart of Apache before testing. Use phpinfo to check the variables are visible to php Oct 15, 2010 at 11:23
  • i used export http_proxy=localhost:8080 export HTTP_PROXY=localhost:8080 is it right?
    – Alexar
    Oct 16, 2010 at 7:30
  • 1
    no one helped .
    – Alexar
    Oct 16, 2010 at 10:27
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"
1
  • thanks. i use Ubuntu and i have currently set proxy for system-wide usage. but it just do not work.
    – Alexar
    Oct 15, 2010 at 9: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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.