Tuesday, November 26, 2013

PHP ini Configuration

Case Study

  • Your php scripts contains many inputs fields and also so many logics. When you execute your scripts its gives a fatal error: PHP Fatal error: Maximum execution time of 120 seconds exceeded in C:\wamp\www\phptest\test.php on line 101
  • You want to upload your database to server using phpmyadmin. You select your sql files and when click upload it gives a fatal error : PHP Fatal error: Files exceeds it Maximum upload size.

The solution is

Configure your php.ini file

PHP ini file location

If you have wamp installed in c drive then go C:\wamp\bin\php\php5.2.6 as shown in below and open php.ini file

Or

You can go directly by clicking wamp tray icon as shown in below. In this case, you have to run wamp server
Now we have our php.ini file ready. So lets do the following

 PHP short open tag

You must off the php short tag for the following reasons
  • Using short tags should be avoided when developing applications or libraries that are meant for redistribution, or deployment on PHP servers which are not under your control, because short tags may not be supported on the target server.
  • For portable, redistributable code, be sure not to use short tags.
  • If you are sharing your code (open source etc.), some users might use them on a host which does not support PHP short code. So do not use short tag.
  • Generates confusion with XML declarations. Your code will break, and you will have very very hard time figuring out why.
  • <% %>, the ASP opening tag! Probably one of the most idiotic 'features' in PHP – the ability to write PHP code with ASP opening tags. Avoid anything idiotic.
  • Even the creators of PHP are suggesting not using short tags. Infact, short tags will be gone in PHP 6. Make your code future-proof.
So keep
short_open_tag = Off

Maximum execution time

Suppose you are running a script that takes more time (more than 30 seconds and your assigned time is 30 seconds) to execute. It gives you a php fatal error : "maximum execution time exceeds" and your script stopped running. So increase execution time
max_execution_time = 60 or max_execution_time = 120

Maximum Input time

Maximum amount of time each script may spend parsing request data. If you think your are running a big script then increase input time.
max_input_time = 60

Memory limit

Maximum amount of memory a script may consume
memory_limit =512M

Display errors

In order to see errors that your scripts generates then keep it on
display_errors = On

Log errors

Keep it on if you want to save any php errors in a file for future use.
log_errors = On

Error log

Location of error log file. Default error log file location is c:/wamp/logs. If you want to some where else than default location change it.
error_log = c:/wamp/logs/php_error.log

Post Maximum Size

Maximum size of POST data that PHP will accept. If your scripts contains audio or video data then increase it
post_max_size = 8M

Upload Maximum Size

Maximum allowed size for uploaded files. If Your scripts contains audio or video data then increase it
upload_max_filesize = 20M

Error Reporting

Suppose you are new in PHP programming and you want to see all sorts of error that your scripts generates then keep it E_ALL. Remember that, keep it on only for development environment , not in production environment.
error_reporting = E_ALL

Restart Wamp

After successfully changing above php configuration, save the file.

Now Don't Forget To Restart Your Wamp Server

Checking Changes value

To see the changes value, go to http://localhost/?phpinfo=1 and see your recently changes php value.




How to backup and download Database using PHP

< ?php $mysqlUserName = 'databaseusername' ; $mysqlPassword = 'databasepassword' ; $mysqlHostNa...