Fixing WordPress error “Allowed memory size of…”

I’ve just updated my WordPress to version 3.2, when update has been finished a page with error code 500 was displayed. In log file had many entry of Fatal error: Allowed memory size of 33554432 bytes exhausted

To know if it your problem too, edit file error_log in wp-admin directory and and take a look at last rows.

The following process fixed this for me, but your host server should allow sizing PHP memory at runtime.

Open and edit file wp-settings.php at root of WordPress directory and put the row bellow after “<?php”:

define('WP_MEMORY_LIMIT', '64M');

Here I’ve set up to 64MB to PHP, but how to know amount of MB to set up?

In error message, the long number means amount of bytes allocated to PHP: “Fatal error: Allowed memory size of 33554432…”. This number represents 32MB (do this calculation to converts byte in megabytes 33554432 / (1024^2) = 32).

Just set a number greater than the result in line above.


How is fight between Firefox, Internet Explorer and Google Chrome?

I’ve was analysing blog access chart and, curiously, I see how are the most usable browsers.

The fight between Firefox and Internet Explorer is old and, little time ago, Microsoft’s browser lost first position to Firefox. Now, with Google Chrome more stable and accessible, the three firsts position may be changed again.

In one year of interval, this blog had 35,738 visits, where the Firefox was most usable browser, responsible for 14,705 (41.75%) of access, distantly followed by Internet Explorer (10,542 access, or 29.5%) and Google Chrome (8,679 access, or 24.29%). Opera came in 4th and Safari came in 5th.

Below the chart generated by Google Analytics with complete list of browsers and amount of access:

Chart generated by Google Analytics between 06/07/2010 and 06/07/2011 (click to zoom)

Will be a matter of time to Internet Explorer to leave second position to Google Chrome


How to read and write CLOB fields

The Character Large Object (or CLOB) is a commonly found in databases and used to store high quantity of characters.

At MySQL, for example, this field is called MEMO.

Writing CLOB field

The method setAsciiStream of PreparedStatement allow to pass data to a CLOB.

ps.setAsciiStream(bindPosition, inputStream, textLength);

bindPosition – Position in PreparedStatment’s CLOB field.
inputStream – Used to pass data.
textLength – Data (text) length.

Full code:

String sql = "INSERT INTO TABLE (text) VALUES(?)";
		try{
			String txt = readTxtFile();
			ByteArrayInputStream bais = new ByteArrayInputStream(txt.getBytes());

			PreparedStatement ps = conexao.prepareStatement(sql);
			//CLOB is '?' at first position
			ps.setAsciiStream(1, bais, txt.length());

			ps.execute();

			ps.close();
		}catch (Exception e) {
			e.printStackTrace();
		}

Retrieving CLOB data

We’re using SELECT clause, this clause returns a ResultSet to fetch data and, calling getClob method, passing column name or your position in the query, it give to you a Clob object.

rs.getClob("xml");

Full code:

String sql = "SELECT xml FROM TEST";
		try{
			PreparedStatement ps = conexao.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();

			while(rs.next()){
				Clob clob = rs.getClob("xml");
				BufferedReader reader = new BufferedReader(clob.getCharacterStream());
				StringBuffer strBuf = new StringBuffer();

				String linha = null;
				while((linha = reader.readLine()) != null){
					strBuf.append(linha);
//Character.LINE_SEPARATOR insert break line
					strBuf.append((char)Character.LINE_SEPARATOR);
				}

				System.out.println("=========== CLOB ===========");
				System.out.println(strBuf.toString());
			}

			rs.close();
			ps.close();
		}catch (Exception e) {
			e.printStackTrace();
		}

That’s it! Easy and painless ;)

Download full code here

To write a BLOB see this tutorial.


Installing .apk packages at Android SDK emulator

Sometimes our applications depends of third-part applications for tests or to access resources of emulator that aren’t available by default.

In directories of SDK, commonly in platform-tools, there is an executable called adb, with it we’ll to install third-part applications.

You will need an application (.apk). Browse internet or copy from your Android smartphone using applications like AppSaver.

- Run the emulator, you can use SDK Manager or Eclipse plugins.

- Using DOS Command (Windows) or terminal (Linux), open directory platform-tools and run commando line below:

$ adb install <.apk path>

This message will be displayed

$ adb install Application.apk
125 KB/s (1091937 bytes in 8.474s)
        pkg: /data/local/tmp/Application.apk
Success

Now, the third-part application is available at emulator menu, like have installed in your smartphone.

Agora o aplicativo estará disponível no menu do emulador. ;)

 


Fix for “JDK not found” error for Android SDK at Windows 7 x64

If you’re trying to install Android SDK on Windows 64 bits and is receiving the error message “JDK not found”, the solution found by http://www.eighthourlunch.com/node/161, basicaly insert some entries at Windows registry, after this, the Google Android SDK will found your JDK instalation.

The .REG file are available here .

Before run file, open it with notepad and change path “C:\\Program Files\\Java\\jdk1.6.0_23″ to your JDK directory, and the path “C:\\Program Files\\Java\\jre6″ to your JRE directory.

This fix has worked for me. ;)


  • AdSense

  • Copyright © 1996-2010 André L. S.. All rights reserved.
    iDream theme by Templates Next | Powered by WordPress