Sunday 28 September 2014

Increase PHP memory limit In WordPress

While working with WordPress , often when we upload large size themes and plugins we face a problem of PHP memory limit in WordPress. WP_MEMORY_LIMIT through which we can increase or decrease the size of PHP memory limit.


You will find this WP_MEMORY_LIMIT in a file wp-settings.php in root directory of WordPress. By default nothing is defined in the file regarding WP_MEMORY_LIMIT  but if you want to increase the memory limit, you need to write a line for the memory limit after this comment in wp-settings.php

// Set initial default constants including WP_MEMORY_LIMIT, WP_MAX_MEMORY_LIMIT, WP_DEBUG, WP_CONTENT_DIR and WP_CACHE.
we need to write below line to to increase the memory limit of PHP for wordpress. To increase PHP memory to 64 MB we need to add this line in wp-settings.php file.
 
define( 'WP_MEMORY_LIMIT', '64M' );

To increase PHP memory to 96 MB we need to add this line in wp-settings.php file.
 
define( 'WP_MEMORY_LIMIT', '96M' );

To increase PHP memory to 128 MB we need to add this line in wp-settings.php file.
 
define( 'WP_MEMORY_LIMIT', '128M' );

Now this increase decrease in memory of PHP in WordPress depends on use of plugins and themes which you are using in WordPress.

Note: Sometimes these settings do not work due to the limitation of Host, As some hosts do not allow to change memory limit of PHP but most of the hosts have limited the PHP limit at 8MB, So you need to contact your host to increase the memory limit.

Validating Email Address Using Regular Expressions In Java


Few days back working on some project, i come across some issue to validate just email in between complete project and email was needed to be validate at multiple places in the code so i thought to write a class like a wrapper Email Validator so that we can use at at any instance. so let me share that email Validator class with you guys. So the important thing that i have used is that i have used regular expression to validate email address. The Email Validator Class is given below.
//Email Validator Class
package EmailValidate;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class EmailValidator {
private Pattern pattern;
private Matcher matcher;
private static final String EMAIL_PATTERN = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
+ "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
public EmailValidator() {
pattern = Pattern.compile(EMAIL_PATTERN);
}
/**
* Validate hex with regular expression
*
* @param hex
* hex for validation
* @return true valid hex, false invalid hex
*/
public boolean validate(final String hex) {
matcher = pattern.matcher(hex);
return matcher.matches();
}
}
As we have wrote wrapper class above now the question arise that how we are going use it as validator of email address.
Validating Email in a JtextField
Emailvalidator emailValidator = new Emailvalidator();
if(!emailValidator.validate(emailField.getText().trim())) {
System.out.print("Invalid Email ID");
/*
Perform any action here that you want to show while email address is invalid 
i-e change the color of the field */
}
Validating Email in Console
I will show this part writing a small program which will ask for email id in console, If the email Id is valid it will print Valid Email else it will print Invalid Email ID. So let's move on with the code
package EmailValidate;
import java.util.Scanner;
public class VEmail {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
System.out.println("Enter email address :");
String EmText = input.next();
EmailValidator emailValidator = new EmailValidator();
if(!emailValidator.validate(EmText.trim())) {
System.out.print("Invalid Email ID");
}
else
{
System.out.print("Valid Email ID");
}
}
}
So that's all for Using Email Validator for multiple purposes by writing a general class.