Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Change the PHP’s maximum allowed form post size

Answer:

The default maximum allowed form post size in PHP is only 8MB. If you want to change it, you need to edit the php.ini

vi /etc/php.ini

Locate and set (16M in the following example)

memory_limit = 16M;
post_max_size = 16M;

Try it with the number you need.

Also, remember to restart web server such as Apache if needed.

Check if an array is associative or sequential in PHP?

Answer:

In PHP, if you want to check if a given array variable is associative or sequential, you can use the following method:

<?php 

$list = array(1, 2, 3, 4, 5);
$is_sequential = array_values($list) === $list;

Change the PHP's maximum upload file size

Answer:

The default maximum upload file size in PHP is only 2MB. If you want to change it, you need to edit the php.ini

vi /etc/php.ini

Locate and set (100M in the following example)

memory_limit = 100M;
post_max_size = 100M;
upload_max_filesize = 100M;

Try it with the number you need. (You might need to use a large value in post_max_size and memory_limit if you want to upload a file which is exactly 100M in size)

Also, remember to restart web server such as Apache if needed.

What is the PHP's short_open_tag

Answer:

PHP's short_open_tag is a way to use PHP in a PHP script without the normal PHP tag, e.g.

Instead of

# <?php echo "hello world"; ?>

You can use a simplified version.

# <? echo "hello world"; ?>

Although it is not recommended, if you want to set it, you can enable it by editing the php.ini

vi /etc/php.ini

Locate and set

short_open_tag = On

Also, remember to restart web server such as Apache if needed.

Validate the syntax of PHP files in a directory

Answer:

To validate the syntax of PHP files in a directory, to check if any syntax error so we can fix them before they really happen at runtime.

You would need to have the GNU parallel installed in order to use the command below.

# find -type f -name '*.php' | parallel php -l