19th September 2007
PHP proxy is simple but good. I converted it into a proxy-function for one of my projects.
Do pay attention to the comments, especially these two:
I had issues with this script (and others) returning 0 for the bytesTotal in flash. Basically, the Content-Length header was absent from the response. By simply adding
header(“Content-length: “.strlen($response)) before the echo, it resolved the issue. I don’t know if there is a more appropriate fix to account for character encoding, etc, but it seems to work.
@Schimmi: Well, if you can add some checks there (like who is referring your script) and allow the access to whitelisted clients (served from your domain)… I think, you can totally make it used applications from same-domain….So it would not be open to world. Yeah above script doesn’t have those things.
Posted in Links, Notepad, PHP, Programming | No Comments »
31st May 2007
Earlier in one of my posts (Using PEAR HTTP_Client or HTTP_Request with HTTP proxy) I gave an example of using PEAR HTTP_Client and/or HTTP_Request from behind an http proxy. However, I didn’t tell how to make PEAR itself work properly from behind an HTTP proxy (e.g., for online operations like “pear upgrade-all”).
So here’s that tiny missing bit of information.
Windows:
Launch regedit, navigate to HKEY_CURRENT_USER\Environment, and create a string value called PHP_PEAR_HTTP_PROXY. Modify that new value to hold the string like: http://proxy_username:proxy_password@proxy_server_address:proxy_port.
Linux:
In the Terminal/Konsole, execute (for a system-wide pear configuration)
sudo pear config-set http_proxy http://proxy_username:proxy_password@proxy_server_address:proxy_port
If your proxy password has symbols, special for the shell (e.g. question or exclamation mark) – enclose full proxy specifications with single-quotes, e.g.
sudo pear config-set http_proxy ‘http://proxy_username:proxy_password@proxy_server_address:proxy_port’
If your HTTP proxy server does not require authentication, then use http://proxy_server_address:proxy_port instead.
I think the strings are completely self-explanatory; however, here’s an example of proxy (with authentication) specification: http://john.smith:CrAzYP433WoRd@192.168.0.1:3128.
Posted in Misc, PHP, Programming | No Comments »
23rd May 2007
Yesterday I needed to put together a rather simple PHP script: it would read the contents of a single pre-configured directory, and randomly select up to a pre-configured number of files. These files were images, and were just dumped as IMG tags into the webpage. I came up with a solution, shown below.
The script is simple, but still it’s easier to use the ready solution than to write your own :).
It is heavily commented, and should be easy to understand.
Read the rest of this entry »
Posted in PHP, Programming, Web | No Comments »
23rd May 2007
Found a nicely illustrated method for running a background shell command from PHP and continuously checking if the process is still running.
Here’s sample code without explanations:
function run_in_background($Command, $Priority = 0)
{
if($Priority)
$PID = shell_exec("nohup nice -n $Priority $Command 2> /dev/null & echo $!");
else
$PID = shell_exec("nohup $Command 2> /dev/null & echo $!");
return($PID);
}
function is_process_running($PID)
{
exec("ps $PID", $ProcessState);
return(count($ProcessState) >= 2);
}
To run something like hmmsearch from the HMMER package, you’d do this:
echo("Running hmmsearch. . .")
$ps = run_in_background("hmmsearch $hmmfile $fastafile > $outfile");
while(is_process_running($ps))
{
echo(" . ");
ob_flush();flush();
sleep(1);
}
Posted in Links, PHP, Programming | 8 Comments »
30th April 2007
When using PHP, the simplest way to find the absolute path of your files/folders on the server is by creating a simple path.php file with the following contents (click on the “Plain text” box header for copy-pasting):
<?php
echo realpath(dirname(__FILE__));
?>
Put the new file anywhere in the web-accessible folder on your server,
then just access that file from your favourite web-browser – and you’ll have the absolute path shown to you.
Alternatively, you may use the following code:
This also should display the absolute path on your server.
Posted in Notepad, PHP, Programming, Web | 17 Comments »
10th March 2007
This is a collection of links related to the multiple-language content in Drupal CMS.
i18n module
i18n: Getting the whole thing to work : http://drupal.org/node/81094
Patch: Translations of menu titles and descriptions: http://drupal.org/node/70919
Translated links: http://drupal.org/node/67814
i18n: menu not expanding with URL-Alias: http://drupal.org/node/80820
There was an alternative module to i18n, but I cannot find it at the moment.
Posted in CMS, Drupal, PHP, Programming, Web | No Comments »