Archive for the ‘php’ Category

PHP Startup: Unable to load dynamic library php_openssl.dll

Sunday, January 4th, 2009

You might get the error: “PHP Startup: Unable to load dynamic library php_openssl.dll. The operating system cannot run %1“, when you are trying to start the apache server in the error.log file.

Basically what this error is trying to mention that there is an issue with your php_openssl.dll and a possible mismatch with other depending libraries. To resolve this, follow the below steps:

1. Rename ’ssleay32.dll’ and ‘libeay32.dll’ in c:\windows\system32 to ’ssleay32.dll.old’ and ‘libeay32.dll.old’ respectively.

2. Copy ’ssleay32.dll’ and ‘libeay32.dll’ from your PHP folder to the system32.

3. Restart the apache webserver.

This should get your problem sorted!!

How to remove all comments in a file

Wednesday, May 14th, 2008

If you are ever stuck in situation where you want to remove all the comments regardless of what they are in a source file. Here’s a small command that you can issue in VIM. It is for pattern search and replace using regex.

Open the file in VIM then

:g/\/\/.\+/s

Above command will look for anything after including the “//” characters which is basically a comment in C, C++, php and several other languages.

php header() function not working!

Sunday, July 29th, 2007

I was going nuts to find the problem why did the header() function didn’t redirect my page in some instance and did in others! Luckily I found this function ‘headers_sent()’ which will tell you if at any given point any headers were sent. If the headers were sent from some other file then this function will give you the file name and the line number from where the unexpected header was sent. Very useful and neat. See the example below, it is from php.net manual page.

Consider the following scenario,

<?php
// Sign out
signOut();

// Redirect back to the main page
header(“Location: http://toronto.eclassifieds4u.com/main);
?>

If for some reason, the header() call to redirect is not working, there won’t be any error messages, making it difficult to debug. However, using headers_sent(), you may easily find the source of the problem.

<?php
// Sign out
signOut();

/*
* If headers were already sent for some reason,
* the upcoming call to header() will not work…
*/
if(headers_sent($file, $line)){
// … where were the mysterious headers sent from?
echo “Headers were already sent in $file on line $line…”;
}

// Redirect back to the main page
header(“Location: http://toronto.eclassifieds4u.com/main);
?>

As the documentation states, “header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.” In the above debugging solution, you will find out exactly where any of these problematic output or blank lines exist. You should then be able to resolve the issues with much more ease than if you hunted for the problems aimlessly.

Fatal error: Unable to read X bytes in file.php

Thursday, May 10th, 2007

If you got this error Fatal error: Unable to read X bytes in file.php, then:

You have encoded your php files using Zend Encoder and uploaded to the server but gives you this error. This problem occurs due to your FTP software which has ftp’ed your file to the server in ascii mode.

To fix, make sure you upload the file in binary mode and not ascii. This will fix your problem.