DeeEmm

Pragmatism in code

Waxing lyrical about life the universe and everything software related since lunchtime 2006.

Increasing server memory limit

If you are experiencing memory issues with scripts, it may be necessary to increase the memory available to the script.

If you have access to your servers php.ini file, this is relatively straightforward -  simply increase the value of the memory_limit directive to 128M then restart apache. However, I'm guessing that if you're reading this post, looking for a solution to memory issues, then the last sentence probably made little sense, and chances are that you do not have access to your servers php.ini file - this is true for most shared servers.

If you do not have access, all is not lost - you can override the value in either a custom php.ini file, or via the htaccess file - the method needed depends on the following:

If PHP is compiled to run as a cgi script then you will need to use a custom php.ini, but if it is compiled to run as a module then you will need to use htaccess. (tip - you can view your servers php_info() to find out which one)

Continue reading
2510 Hits
0 Comments

Nowdoc string handler

Some of you may be familiar with the heredoc string handler which allows multi-line strings to be easily assigned to a variable, this great tool has many uses - such as retaining pre-formatted layout and improving the readability of code. The heredoc handler also parses variables contained within the string - much the same way that using double quotes does. Replacing any variables with their respective values

This has some not so obvious drawbacks, one of which i discovered whilst trying to inject complex PHP code into a database for later evaluation via the eval() statement. (please don't ask why)

The problem I found was that whilst it was easy to escape the string so that it would not break the SQL statement, The same escape characters also broke the evaluation. This might not have been an issue in any other situation, but for this particular project i did not have access to the code that carried out the evaluation so that I could strip the escape characters out before running the eval query.

However, PHP 5.3 has now introduced the nowdoc syntax - this basically operates in the same manner as heredoc, but does not parse any of the content. This means that not only are variables not parsed, but neither are any characters that would normally require escaping. In essence, any string read into a variable by the nowdoc handler will not require any escaping whatsoever.

Continue reading
2145 Hits
0 Comments