Autarchy of the Private Cave

Tiny bits of bioinformatics, [web-]programming etc

    • Archives

    • Recent comments

    Archive for the 'PHP' Category

    PHP proxy

    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.

    Share

    Posted in Links, Notepad, PHP, Programming | No Comments »

    How to convert between utf8 and cp-1251 without iconv or mbstring

    8th July 2007

    This helped me, maybe it will help you: How to convert between utf8 and cp1251 without iconv
    Read the rest of this entry »

    Share

    Posted in Links, PHP, Programming, Web | No Comments »

    How to make PEAR work from behind an HTTP proxy (Windows and Linux)

    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.

    Share

    Posted in Misc, PHP, Programming | No Comments »

    Directory-based random image rotation PHP script

    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 »

    Share

    Posted in PHP, Programming, Web | No Comments »

    Executing and checking background shell process from PHP

    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:

    1. function run_in_background($Command, $Priority = 0)
    2. {
    3.  if($Priority)
    4.   $PID = shell_exec("nohup nice -n $Priority $Command 2> /dev/null & echo $!");
    5.  else
    6.   $PID = shell_exec("nohup $Command 2> /dev/null & echo $!");
    7.  return($PID);
    8. }
    9.  
    10. function is_process_running($PID)
    11. {
    12.  exec("ps $PID", $ProcessState);
    13.  return(count($ProcessState) >= 2);
    14. }

    To run something like hmmsearch from the HMMER package, you’d do this:

    1. echo("Running hmmsearch. . .")
    2. $ps = run_in_background("hmmsearch $hmmfile $fastafile > $outfile");
    3. while(is_process_running($ps))
    4. {
    5.  echo(" . ");
    6.  ob_flush();flush();
    7.  sleep(1);
    8. }
    Share

    Posted in Links, PHP, Programming | 8 Comments »

    How to find absolute path on a web-server (using PHP)

    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):

    1. <?php
    2. echo realpath(dirname(__FILE__));
    3. ?>

    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:

    1. <?php
    2. echo getcwd();
    3. ?>

    This also should display the absolute path on your server.

    Share

    Posted in Notepad, PHP, Programming, Web | 17 Comments »

    Drupal internationalization (i18n) and localization (l10n)

    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.

    Share

    Posted in CMS, Drupal, PHP, Programming, Web | No Comments »