Showing posts with label pac. Show all posts
Showing posts with label pac. Show all posts

Wednesday, 13 June 2012

FindProxyForURL - Parse a PAC (proxy auto config) file in PHP

Proxy servers are used in most companies as a gateway to the internet, that do other things like cache results and check web requests and responses.  A PAC file is a Javascript file evaluated by web browsers to determine which proxy server to use for certain URL's.  For example, some URL's can go straight to the internet, or a local server, and others must be sent to one of the proxy servers.

One day I needed to run this javascript from php on the web server, to find the proxy in the same way; then php could also follow the same proxy rules as desktop computers in my office.

Here's a working example of using the php_spidermonkey extension to run a proxy auto config script (javascript) in PHP.