install: /usr/ports/…/doc/: Inappropriate file type or format

While I tried to upgrade both of my FreeBSD server (9 & 10) today, I got the following error:

install: /usr/ports/…/doc/: Inappropriate file type or format

Actually, here is the complete error message:

===>  Staging for memcached-1.4.17_1
===>   memcached-1.4.17_1 depends on shared library: libevent-2.0.so - found
===>   Generating temporary packing list
/usr/bin/make  install-recursive
Making install in doc
/usr/bin/make  install-am
test -z "/usr/local/man/man1" || /bin/mkdir -p "/usr/ports/databases/memcached/work/stage/usr/local/man/man1"
 install  -o root -g wheel -m 444 memcached.1 '/usr/ports/databases/memcached/work/stage/usr/local/man/man1'
test -z "/usr/local/bin" || /bin/mkdir -p "/usr/ports/databases/memcached/work/stage/usr/local/bin"
  install  -s -o root -g wheel -m 555 memcached '/usr/ports/databases/memcached/work/stage/usr/local/bin'
test -z "/usr/local/include/memcached" || /bin/mkdir -p "/usr/ports/databases/memcached/work/stage/usr/local/include/memcached"
 install  -o root -g wheel -m 444 protocol_binary.h '/usr/ports/databases/memcached/work/stage/usr/local/include/memcached'
install  -o root -g wheel -m 555 /usr/ports/databases/memcached/work/memcached-1.4.17/scripts/memcached-tool /usr/ports/databases/memcached/work/stage/usr/local/bin
install  -o root -g wheel -m 444 /usr/ports/databases/memcached/work/memcached-1.4.17/doc/ /usr/ports/databases/memcached/work/stage/usr/local/man/man1
install: /usr/ports/databases/memcached/work/memcached-1.4.17/doc/: Inappropriate file type or format
*** [post-install] Error code 71

Stop in /usr/ports/databases/memcached.
*** [install] Error code 1

Stop in /usr/ports/databases/memcached.

Initially, I thought the problem was caused by the syntax error of the code, therefore, I tried to do the following:

#Shut down the server
sudo /usr/local/etc/rc.d/memcached stop

#Remove Memcached from the system
sudo make deinstall

#Clean up the package
sudo make clean

#Compile the package
sudo make

#Install the package
sudo make install

Unfortunately, it still gave the same error message. I noticed that the error message has something to do with the documentation, so I decide to remove the documentation option in the installation page, i.e.,

#Enter the package setup
sudo make config

#Remove the "doc" option.

Unfortunately, it still gave the same response. I then tried to investigate the cause of the error. So I tried to copy the error command and re-ran it:

install  -o root -g wheel -m 444 /usr/ports/databases/memcached/work/memcached-1.4.17/doc/ /usr/ports/databases/memcached/work/stage/usr/local/man/man1

Which return the exact the same error message:

install: /usr/ports/databases/memcached/work/memcached-1.4.17/doc/: No such file or directory

So I came up an idea. Since I don’t really need the documentation, why not I disable the document option?

cd /usr/ports/databases/memcached

sudo nano Makefile

Change the following from:

post-install:
        ${INSTALL_SCRIPT} ${WRKSRC}/scripts/memcached-tool ${STAGEDIR}${PREFIX}/bin
        ${INSTALL_MAN} ${WRKSRC}/doc/${MAN1} ${STAGEDIR}${MAN1PREFIX}/man/man1
        @${MKDIR} ${STAGEDIR}${DOCSDIR}

To:

post-install:
        ${INSTALL_SCRIPT} ${WRKSRC}/scripts/memcached-tool ${STAGEDIR}${PREFIX}/bin
#        ${INSTALL_MAN} ${WRKSRC}/doc/${MAN1} ${STAGEDIR}${MAN1PREFIX}/man/man1
        @${MKDIR} ${STAGEDIR}${DOCSDIR}

That’s right, I just want to comment out the installation of the man/documentation part. Now, let’s try to reinstall the package again.

#sudo make install

Guess what, it works! Have fun!

–Derrick

Our sponsors:

[PHP]How to delete Memcache variables in PHP?

I’ve never thought about deleting a Memcache key is a difficult task. It took me few hours to figure out a working solution. No kidding. FYI, I am using PHP 5.4

Suppose you store a very expensive data into the Memcache, and you decide to delete it later. According to the PHP documentation, it should be very simple:

$memcache_obj->delete('key_to_delete');

or

memcache_delete($memcache_obj, 'key_to_delete');

However, this method only works with scalar variables, such as string, integer, double, float, Boolean etc. It does not work with non-scalar variables such as array, object etc.

I have tried many different ways, such as setting the value to something else, e.g.,

$memcache->set('key_to_delete', 'deleted');

or making the key to expire immediately:

$memcache->set('key_to_delete', 'deleted', 0, 1);
$memcache->set('key_to_delete', 'deleted', 0, -1);

Unfortunately, none of these methods worked in my case (my variable is a non-scalar array). So, I ended up doing it in a low-level way: Bypassing the PECL-Memcache (PHP Library) and talk to the Memcache server directly. Guess what, it works very well. The variable gets deleted!

function MEMCACHE_DEL_HASH($key){
	
	if ($key == '') return FALSE;
	
	$socket = @fsockopen('localhost', 11211);
	$command = "delete {$key}";
	
	fwrite($socket, $command."\r\n");
	fclose($socket);
	
	return true;
}

And it is super easy to call this function:

MEMCACHE_DEL_HASH('key_to_delete');

Feel free to modify this function such that you can pass in the connector, port or do anything you like.

That’s it! Have fun with Memcache.

–Derrick

Our sponsors:

Tokyo Cabinet is 31 times faster than MySQL!!!

Today I was comparing the performance of Tokyo Cabinet, MySQL and Memcached using PHP. The result of Tokyo Cabinet is really impressive!

(Note that these results are generated from my computer. If you perform your own benchmarks, then you might find different results due to different system configurations. In fact, I encourage you to perform your own benchmarks. )

1. Quick Result

Total time used to write 10000 records and retrieve them back by each candidate  (The lower the better):
Tokyo Cabinet: 18.87s
Memcached: 11.309s
MySQL: 562.21s

A completed result will be given below.

2. Testing environment

Hardware

  • Intel Pentium II 450MHz
  • 160 MB RAM

Software

  • FreeBSD 7.2
  • Apache 2.2.11
  • PHP 5.2.9
  • Tokyo Cabinet 1.4.20
  • Tokyo Tyrant 1.1.26
  • MySQL 5.1.34
  • Memcached 1.2.6

3. Test scenario

For each candidate, I measure its performance using the following strategies through PHP:

1.) The time used to create all of the necessary objects.

2.) The time used to connect to the database.

3.) The time used to store 10000 randomly generated data.

4.) The time used to read 10000 randomly generated data.

5.) The time used to close the connection.

4. Test results

Tokyo Cabinet

time index ex time %
Start 1243136772.72818600 0.00%
create 1243136772.72838700 0.000201 0.00%
connect 1243136772.73224200 0.003855 0.02%
vanish 1243136772.73526800 0.003026 0.02%
put 1243136781.53287200 8.797604 46.60%
get 1243136791.60574800 10.072876 53.35%
close 1243136791.60755900 0.001811 0.01%
Stop 1243136791.60782300 0.000264 0.00%
total 18.879637 100.00%


Memcached

time index ex time %
Start 1243131185.86078100 0.00%
create 1243131185.86092500 0.000144 0.00%
connect 1243131185.86688300 0.005958 0.05%
put 1243131191.49702900 5.630146 49.78%
get 1243131197.16868100 5.671652 50.15%
close 1243131197.16982400 0.001143 0.01%
Stop 1243131197.17003400 0.000210 0.00%
total 11.309253 100.00%

MySQL

time index ex time %
Start 1243136138.19049000 0.00%
create 1243136138.19064700 0.000157 0.00%
connect 1243136138.22529900 0.034652 0.01%
put 1243136150.70760600 12.482307 2.22%
get 1243136700.40063700 549.693031 97.77%
close 1243136700.40078900 0.000152 0.00%
Stop 1243136700.40104500 0.000256 0.00%
total 562.210555 100.00%

The overhead time (create objects, making connections, closing connections etc) of all candidates are about the same. The only difference is storing the record and retrieving the record. Both Tokyo Cabinet and MySQL took about 10 seconds to store 10000 records in the database. However, Tokyo Cabinet took about 10 seconds to retrieve the records while MySQL took about 550 seconds! That’s about 31 times longer!

benchmark-tokyocabinet-memcached-mysql

5. Materials

Here is the material I used to make this benchmark test.
Click here to download the package.

Please feel free to let me know if you have any question or comment.

Our sponsors:

Installing Apache, PHP, MySQL and MemCached on OS X

This is my note on how to to install Apache, PHP and MySQL on a an OS X box. Although some of these applications are come with the operating systems, it is always good to know how to upgrade them to the latest version.

1. Apple Developer Tools and Mac Port

Before installing Mac Port, you will need the Apple Developer Tools. You can download it from the Apple Developer’s Network.

After installing Apple Developer’s Tools, you can install Mac Port. You can get it from the here.

Update Mac Port

sudo port selfupdate

Add the Mac Port path in the profile: ”’~/.bash_profile”’:

export PATH=/opt/local/bin:$PATH

MySQL:Mac Port
Install MySQL from Mac Port:

sudo port install mysql5

MySQL:Package
Go to the [http://dev.mysql.com/downloads/mysql/5.0.html#macosx-dmg MySQL’s website] to download the package.

Setup the a master password for root user:

/usr/local/mysql/bin/mysqladmin -u root password 'new-password'

Add the MySQL path in the profile: ”’~/.bash_profile”’:

export PATH=/usr/local/mysql/bin:$PATH

Apache:Mac Port

Install Apache from Mac Port:

sudo port install apache2

Open the configuration file: ”’/opt/local/etc/rc.conf”’ and add the following at the end of the file:

APACHE2=-YES-

PHP:Mac Port

Install PHP from Mac Port:

sudo port install php5 +apache2 +mysql5 +pear 

When that is done, register PHP 5 with Apache 2:

cd /opt/local/apache2/modules
sudo /opt/local/apache2/bin/apxs -a -e -n "php5" libphp5.so

And create a php.ini file (which you can edit to configure PHP 5):

sudo cp /opt/local/etc/php.ini-dist /opt/local/etc/php.ini

httpd.conf

Edit the Apache configuration file ”’/opt/local/apache2/conf/httpd.conf”’ and add the following lines to the end of the file:

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

Replace this line:

DirectoryIndex index.html

by the following:

DirectoryIndex index.php index.html

php.ini

If the MySQL is installed from package rather than from Mac Port, we need to modify the mysql.default_socket value.

Open ”’/opt/local/etc/php.ini”’:

mysql.default_socket = /tmp/mysql.sock

MemCached

Install MemCached from Mac Port:

 sudo port install memcached
 sudo port install php5-memcache

We need to enable MemCached in PHP5.

First, we need to add the following in ”’/opt/local/etc/php.ini:”’:

extension_dir=/opt/local/lib/php/extensions/no-debug-non-zts-20060613
extension = memcache.so

Run the following command to start MemCached:

sudo /opt/local/bin/memcached -d -u nobody

Our sponsors:

Installing Apache, PHP, MySQL and MemCached on FreeBSD

This is my note on how to to install Apache, PHP, MySQL and MemCached on a FreeBSD 7 Box.

1. MySQL

Go to the mysql52-server port directory by typing the command:

cd /usr/ports/databases/mysql51-server

Build the port by typing:

make BUILD_OPTIMIZED=yes BUILD_STATIC=yes

Using these two options will speed up the execution time.

Install the port by typing:

make install clean

Open the configuration file: ”’/etc/rc.conf”’ and add the following at the end of the file:

mysql_enable="YES"

Copy the default configuration file:

cp /usr/local/share/mysql/my-medium.cnf /etc/my.cnf

Start mysql manually to avoid having to reboot now by typing:

/usr/local/etc/rc.d/mysql-server start

Setup the a master password for root user:

/usr/local/bin/mysqladmin -u root password 'new-password'

2. Apache

Go to the apache22 port directory by typing the command:

cd /usr/ports/www/apache22

Install the port by typing:

make install clean

Open the configuration file: ”’/etc/rc.conf”’ and add the following at the end of the file:

apache22_enable="YES"

Add the following in: ”’/boot/loader.conf”’

accf_http_load=YES

3. PHP

3.1 PHP5

Go to the php5 port directory by typing the command:

cd /usr/ports/lang/php5

Install the port by typing:

make install clean

Make sure the APACHE (Build Apache module) option is checked.

3.2 PHP5 Extentions

Note: If you need to install PDF-Lite, please do the following:

fetch ftp://ftp.swin.edu.au/gentoo/distfiles/PDFlib-Lite-7.0.2.tar.gz
sudo mv PDFlib-Lite-7.0.2.tar.gz /usr/ports/distfiles/

Go to the php5 extensions port directory by typing the command:

cd /usr/ports/lang/php5-extensions

Make sure sockets is selected.

Install the port by typing:

make install clean

Install the php.ini file:

cp /usr/local/etc/php.ini-dist /usr/local/etc/php.ini

3.3 Enable PHP in Apache

3.3.1 httpd.conf

Edit the Apache configuration file ”’/usr/local/etc/apache22/httpd.conf”’ and add the following lines to the end of the file:

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

Replace this line:

DirectoryIndex index.html

by the following:

DirectoryIndex index.php index.html
3.3.2 httpd-languages.conf

Edit the Languageconfiguration file ”’/usr/local/etc/apache22/extra/httpd-languages.conf”’ and add the following lines to the end of the file:

AddDefaultCharset On

Startup the Apache:

/usr/local/etc/rc.d/apache22 start

4. MEMCached

Go to the pecl-memcache port directory by typing the command:

cd /usr/ports/databases/pecl-memcache

Install the port by typing:

make install clean

Go to the memcached port directory by typing the command:

cd /usr/ports/databases/memcached

Install the port by typing:

make install clean

Open the configuration file: ”’/etc/rc.conf”’ and add the following at the end of the file:

memcached_enable="YES"

To start using MemCached without rebooting, type:

/usr/local/bin/memcached -d -u nobody

–Derrick

Our sponsors: