Categories
Computing Mac OS X PHP Web Development

Enabling Oracle OCI8 PHP Extension on OS X Snow Leopard

My current project involves using PHP with an Oracle database. Oracle apparently embraces PHP warmly and as such supports an open source database driver for the environment called OCI8. As a Mac user I was looking to use OS X's built-in Apache and PHP setup, which like many PHP installations does not have the Oracle OCI8 driver installed or enabled. It took me some time and research to get it up and running. I was using Oracle Express, a limited capability, free-ish version of Oracle's database. Oracle Express was installed on a separate Windows machine as it cannot run or be installed on Snow Leopard. I also assume that you enabled PHP in your Apache configuration (/etc/apache2/httpd.conf) and have a /etc/php.ini by copying it from /etc/php.ini.default.

OCI8 relies on OS X having several client libraries and tools from Oracle installed on OS X. For most intents and purposes download the 64-bit version of the following files under the title "Version 10.2.0.4 (64-bit)": 

Registration is required for all downloads.

Share
Categories
PHP Web Development

PHP: Headers cannot be sent or why is headers_sent() incorrect?

Working with PHP, trying to warm up to PHP 5 with all its object-oriented glory, or at least step forward compared to PHP 4.

When you redirect browsers in PHP, you do it raw, without niceties of objects, by sending the HTTP header to the client with a call like:

header(“Location: “);

For some odd reason, this kept on failing, with an error message telling me that the header cannot be sent. Furthermore, PHP even told me through its header ‘detection’ method php headers_sent() that the headers were indeed sent.

Googled and found this article that infers that the issue may have something to do with file encoding. The file that was causing the issues for me was copied from a Windows machine (I am developing on a Linux VM now). It had the Windows line separators (\r\n). Apparently this made Apache and PHP on Linux very very uneasy and made them think that the headers were sent out.

Resolution: Copy the contents of the file to another file that was born on Unix and uses its line separators (\n). Ugly moments in coding.

Share
Share