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.

Dec 082010
 

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

Nov 182010
 

Is PHP pass by reference or pass by value?

Answer:

PHP is pass by value, see the code below:

<?php

class Dog {
	
	public $name;

	public function __construct($name) {
		$this->name = $name;
	}

}

function bar($dog) {
	$dog = new Dog("bar");
	echo $dog->name;
}

$d = new Dog("foo");
echo $d->name;

bar($d);
echo $d->name;

If PHP is pass by reference, the last echo statement will print out "bar" instead of "foo", which is not true.

Oct 082010
 

Set the maximum execution time in PHP

Answer:

The default maximum execution time in PHP is 30 seconds. If you want to change it, you need to edit the php.ini

vi /etc/php.ini

Locate and set

max_execution_time = 120;

Try it with the number you need.

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

Sep 302010
 

Use of ASP like tags in PHP

Answer:

In PHP, you can use ASP-like <% %> tags in addition to the usual <?php ?> tags. But you need to enable it before use.

You need to editing the php.ini

vi /etc/php.ini

And set

asp_tags = 1

Restart your web server if needed.