Autarchy of the Private Cave

Tiny bits of bioinformatics, [web-]programming etc

    Archive for the 'PHP' Category

    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:

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

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

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

    PHP:
    1. <?php
    2. ?>

    This also should display the absolute path on your server.

    Share

    Posted in Notepad, PHP, Programming, Web | 12 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 »

    dotProject 2.0.4/2.1.2/2.1.3 on shared hosting

    22nd January 2007

    Update: the same solution seems to still apply to dotProject 2.1.2; the post instructions have been modified for dP 2.1.2.

    Update 2: fsmullin suggested a method to fix a similar error in index_table.php, the files_count_max cannot be found error when you click the FILES tab/menu item. His suggestion is now incorporated into the post.

    Update 3: this post is still relevant for dotProject 2.1.3.

    In one of my recent posts about project management software I stated the desire to extensively test dotProject 2.0.4. However, many shared hosting providers appear incompatible with dotProject: the right to CREATE TEMPORARY TABLES in MySQL is not granted, but is needed by dotProject.

    Here's sample error (2.0.4):

    query failed(CREATE TEMPORARY TABLE tasks_sum SELECT task_project, COUNT(distinct task_id) AS total_tasks,
    SUM(task_duration * task_percent_complete * IF(task_duration_type = 24, 8.0, task_duration_type))/
    SUM(task_duration * IF(task_duration_type = 24, 8.0, task_duration_type)) AS project_percent_complete FROM `tasks` GROUP BY task_project)

    For 2.1.2, sample error would be:

    Table 'tasks_total' doesn't exist

    I tried looking for solutions, and here's what I found...
    Read the rest of this entry »

    Share

    Posted in PHP, Programming, Software, Web | 10 Comments »