12th March 2008
Note: this post is based on the comment by Simon, who generously shared his experience.
Step-by-step:
- Download the compiled ffmpeg with libmp3lame support (direct download links: older version ffmpeg.with.lame and newer version ffmpeg.2007-10-28.with-libmp3lame-support).
- Rename the downloaded executable file to "ffmpeg" (no extension), upload it to the directory on your server (in this example /home/myusername/).
- Download libmp3lame.so.0.
- Upload libmp3lame.so.0 to the same directory where you placed ffmpeg in.
- Create a php file with the following code (remember to change the paths to your own, where you actually uploaded binaries in previous steps):
PHP:
-
<?php
-
exec("export LD_LIBRARY_PATH=/home/myusername/");
-
-
?>
- If you access that PHP file with your browser, you should be able to see a list of formats which are supported by ffmpeg, and if you find "EA libmp3lame" somewhere in the output, then it means you now can Encode Audio in libmp3lame!
- If that doesn't work for you: LD_LIBRARY_PATH can be a protected variable in PHP (you can check for this by searching for the "safe_mode_protected_env_vars" value in phpinfo() output). The workaround here can be to write your commands to a file from php, then chmod that file with 0775 permissions (rwx-rx-rx), and run the file through exec(). In this way, PHP is not changing the LD_LIBRARY_PATH, but telling the server to run a file, which tells the server to change it. This method worked for the original author of these instructions.
For passing arguments to the PHP wrapper script - check out PHP's $argv variable (more on this here). If you decided to use shell-script as a wrapper for "export LD_LIBRARY_PATH", then using $1, $2 etc will allow you to pass parameters to the shell script, e.g. in the example below
CODE:
-
export LD_LIBRARY_PATH=/home/myusername/
-
/home/myusername/ffmpeg -i /home/myusername/$1 $2 /home/myusername/$3
you could pass "input file" as first argument, "parameters" as second and "output file" as third to make such a wrapper script work.
Share This
Posted in *nix, PHP, Programming, Software, Web | 9 Comments »
8th February 2008
Most frequent use: convert database from latin1_swedish to utf8_general_ci.
Original script found at: MySQL and UTF-8.
Update: the original script had an error, it would generate queries likes this one (note the bold part):
ALTER TABLE `links` CHANGE `link_rel` `link_rel` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT NULL;
This is clearly wrong syntax (and logic). I fixed this by making comparison to NULL strict (with three equal signs instead of two):
// Does the field default to null, a string, or nothing?
if ($row['Default'] === NULL)
Update 2: based on comment by banesto, I modified the script; now it does not require specifying the from_collation, it's sufficient to specify to_collation (which will be used for all the fields and tables). The modified code is:
if ($row['Collation'] == '' || $row['Collation'] == $convert_to)
continue;
Here's the script itself: (to copy-paste: first click the "Plain text" header)
Read the rest of this entry »
Share This
Posted in Links, Notepad, PHP, Programming, Web | 28 Comments »
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 This
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 (this is Windows-specific).
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.
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: http://john.smith:CrAzYP433WoRd@192.168.0.1:3128.
This topic is covered somewhere in documentation, I think. There are also other ways to configure HTTP proxy for use by PEAR, the above-presented method is just one of the several possible.
Share This
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 »
Share This
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:
PHP:
-
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:
PHP:
-
echo("Running hmmsearch. . .")
-
$ps = run_in_background("hmmsearch $hmmfile $fastafile> $outfile");
-
while(is_process_running($ps))
-
{
-
-
-
-
}
Share This
Posted in Links, PHP, Programming | No 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):
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.
Share This
Posted in Notepad, PHP, Programming, Web | No Comments »
10th March 2007
This is a collection of links related to the multiple-language content in Drupal CMS.
Drupal i18n report: http://www.developmentseed.org/blog/book/print/376
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 This
Posted in CMS, Drupal, PHP, Programming, Web | No Comments »
22nd January 2007
In one of my recent posts about project management software I stated the desire to extensively test dotProject 2.0.4. However, GoDaddy.com shared hosting appears incompatible with dotProject: the right to CREATE TEMPORARY TABLES in MySQL is not granted, but is needed by dotProject.
Here's sample error:
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)
I tried looking for solutions, and here's what I found...
Read the rest of this entry »
Share This
Posted in PHP, Programming, Software, Web | 3 Comments »
9th December 2006
As described in my previous post, there are some rather simple mechanisms to enable visitor's browser to cache content, and avoid unnecessary load on your servers. In this post I'll take a look at some parts of the practical implementation of the caching mechanism on the server, using PHP.
Read the rest of this entry »
Share This
Posted in PHP, Programming, Web | 1 Comment »
18th October 2006
In this post: some caching-related HTTP request and response headers discussed.
Modern websites are "dynamic" by nature - content you get depends on a number of variables and conditions. The simplest example - being a "guest" or a "registered" user of some forum; in both cases you get content generated by the same script/program, but it differs because of your "registered" state.
Another example - web-photogallery. By design, it is wise to always keep the original photo (the largest and presumably of the highest quality). When gallery visitor's browser requests any smaller version of the photo - we can dynamically resize (often downsize) the original and feed the resulting photo to the browser. This scheme works OK until your gallery gets more and more visitors - CPU load climbs up and increases wait time when accessing your gallery. Evidently, caching is needed.
Read the rest of this entry »
Share This
Posted in PHP, Programming, Web | 2 Comments »
8th September 2006
Last updated: February 19, 2008.
The newest script version migrates from PHP-Nuke 6.5 to Drupal 5.x.
Download the latest version of the migration script.
In 2002 I set up a PHPNuke-6.0 - based portal. Eventually it died due to the lack of time investments and support from collaborators. Now, when time came to revive the project, I made a search and decided to use Drupal as a base CMS for the portal.
In order to migrate userbase from an old portal to the new Drupal-powered one, and following the topic at drupal.org, I found a script and its modification.
I used it to migrate only users, and made some cosmetic changes:
- added options for custom phpnuke table prefixes
- default user name is now = uname (login), not 'temp_name', as before
- I replaced hard-coded links to 'migrate.php' with links to $_SERVER['PHP_SELF'], so that if you rename the script you don't have any problems with that
- now forum topics should not be promoted to the main page (changed 1 to 0 as hinted by Alexis)
Finally, I would like to thank both Karthik Kumar for the original script and Alexis Bellido for the 6.0_to_4.7 modification.
Read the rest of this entry »
Share This
Posted in CMS, Drupal, PHP, Programming, Web | 63 Comments »
6th September 2006
Sometimes, writing automatic HTML forms processors, you need to post several values with the same name of the form field, e.g.:
collection_gene = str_chrom_name
collection_gene = gene_stable_id
This is against the RFC on form fields design and submitting, but this approach is used - for example, by Ensembl. I spent some time to figure out how to make HTTP_Client and HTTP_Request submit multiple 'name-value' pairs instead of one (the latest defined, which overrides the previous). The solution is extremely simple:
Read the rest of this entry »
Share This
Posted in Bioinformatics, PHP, Programming, Science | No Comments »
6th September 2006
If you fetch large amounts of data (e.g. over 2MB per request) using HTTP_Client (or HTTP_request), you may get "out of memory" fatal errors, especially if:
- memory_limit is set to default 8M, and
- you process multiple pages using single non-reset instance of HTTP_Client object.
This problem can manifest itself by producing fatal error after a couple of cycles of successful page retrieval - but always, if run with the same parameters, after some constant or only slightly variable number of cycles.
In my case the problem was that HTTP_Request (a dependancy of HTTP_Client) was holding in memory all the previously fetched pages of the current session (the 'history' feature). To force HTTP_Request to hold only the most recent page, you need to 'disable' history after creating the HTTP_Client or HTTP_Request object instance:
PHP:
-
$req = &new HTTP_Client($params, $headers);
-
// disable history to save memory
-
$req->enableHistory(false);
Hope this helps you.
Share This
Posted in Bioinformatics, PHP, Programming, Science | No Comments »
6th September 2006
If you happen to write PHP script, which uses either HTTP_Client or its dependancy HTTP_Request from PEAR, and the script is supposed to work through the HTTP proxy - here are the sample settings you need:
PHP:
-
$params['proxy_user'] = 'proxy_username';
-
$params['proxy_pass'] = 'proxy_password';
-
$params['proxy_host'] = 'proxy_hostname_or_ip';
-
$params['proxy_port'] = 8080; // 3128, ...
-
-
// I assume $headers were set somewhere else
-
$req = &new HTTP_Client($params, $headers);
If your proxy does not need authorization - just drop the proxy_user and proxy_pass parameters.
Share This
Posted in PHP, Programming | 1 Comment »