How to install PHP APC in CentOS

I assume you already have PEAR/PECL available. I am using the CentOS’s stock PHP. First you need to update your channels:

[code lang=”bash”]kahwee:~ kahwee$ sudo pear update-channels
Updating channel “doc.php.net”
Channel “doc.php.net” is up to date
Updating channel “pear.php.net”
Channel “pear.php.net” is up to date
Updating channel “pecl.php.net”
Channel “pecl.php.net” is up to date[/code]

Continue reading “How to install PHP APC in CentOS”

How to install PHP APC in OS X

I assume you already have PEAR/PECL available. I am using the Mac OS X PHP environment that is provided by Apple’s XCode but it shouldn’t matter how you get your PHP. First you need to update your channels:

[code lang=”bash”]kahwee:~ kahwee$ sudo pear update-channels
Updating channel “doc.php.net”
Channel “doc.php.net” is up to date
Updating channel “pear.php.net”
Channel “pear.php.net” is up to date
Updating channel “pecl.php.net”
Channel “pecl.php.net” is up to date[/code]

Continue reading “How to install PHP APC in OS X”

How to install PHP APC through PEAR

If you try to install PHP APC 3.1.5 through PHP PEAR and encounter errors regarding phpize or the following:

[code lang=”bash”]/usr/include/php5/ext/pcre/php_pcre.h:29:18: error: pcre.h: No such file or directory[/code]

…well don’t worry. You’re missing a few components. For phpize, you’ll need the php5-dev that you can fetch from Ubuntu. For the php_prce.h error, you’ll need pcre3-dev package which is essentially Perl 5 Compatible Regular Expression Library – development files.

Perform the following and install PHP APC using PECL again:

[code lang=”bash”]sudo apt-get install libpcre3-dev php5-dev
sudo pecl install apc-3.1.5[/code]

And it’s done:

[code lang=”bash”]Build process completed successfully
Installing ‘/usr/lib/php5/20090626+lfs/apc.so’
install ok: channel://pecl.php.net/APC-3.1.5
configuration option “php_ini” is not set to php.ini location
You should add “extension=apc.so” to php.ini[/code]

This is tested against Ubuntu 10.04 as well as Ubuntu 10.10 environments.

You can add it to /etc/php5/conf.d/apc.ini by:

[code lang=”bash”]nano /etc/php5/conf.d/apc.ini[/code]

Add in the following codes:

[code lang=”php”]
extension=apc.so
apc.enabled=1
apc.shm_segments=1
apc.shm_size=32M
apc.cache_by_default=1
apc.stat=1
apc.rfc1867=1 //For Drupal upload progress.
apc.stat=7200 //2 hours
[/code]

jQuery’s getJSON failing randomly in Internet Explorer

getJSON is perhaps the easiest method to erm get JSON with JavaScript using jQuery. JSON stands for JavaScript Object Notation, more information at Wikipedia.

The following piece of code is a really simple way to implement AJAX using the jQuery library:

I have a setInterval and each time Firefox will get the updated chat JSON every 10 seconds. But Internet Explorer has some issues, often return with old data.

And this is because of cache! The following code re-implements the above code to avoid caching issues.

To get back your data as JSON, remember to set dataType as “json”.

What cache: false does is that it appends a string of numbers such as “_=1211276828515” at the end of the URL.

GET http://localhost/chat.php?type=json&_=1211276828515

This number increases, it might be string of time in milliseconds or something, but it makes the browser thinks that the request is different from the previous.

I sat in front of the computer for an hour trying to figure out what’s wrong with my JavaScript or PHP code. Defeated by cache.