Crete PHP Cron Jobs in LunarPages Host Server

Categories: PHP; Tagged with: ; @ May 13th, 2014 23:15

Go to Cpanel > Cron Jobs, create new cron job.

Select / modify the scheduling, then add the command:

php /home/xx/public_html/job.php

or

/usr/local/cpanel/3rdparty/bin/php /home/xx/public_html/job.php

Monitoring Website using PHP file_get_contents and mail function

Categories: PHP; Tagged with: ; @ May 13th, 2014 22:20

As a lazy user, I want to get alerted when website goes down.

Solution:

	$homepage = file_get_contents('http://,monitoring--domain.com/');
        if(strlen($homepage) > 0) {
                echo "Got response, no action";
        }else {
                echo "No response from server, send out email...";
                $to      = 'test@test.com';
                $subject = 'Weak up, you website is down!';
                $message = 'Weak up, you website is down!';
                $headers = 'From: webmaster@example.com' . "\r\n" .
                'Reply-To: webmaster@example.com' . "\r\n" .
                'X-Mailer: PHP/' . phpversion();
                mail($to, $subject, $message, $headers);
        }

Run Shell command using PHPShell in your shared host

Categories: PHP; Tagged with: ; @ June 23rd, 2012 13:19

PHP has a shell_exec command: “Execute command via shell and return the complete output as a string ” http://php.net/manual/en/function.shell-exec.php

And here is a project: http://phpshell.sourceforge.net/

PHP Shell

PHP Shell is a shell wrapped in a PHP script. It’s a tool you can use to execute arbitrary shell-commands or browse the filesystem on your remote webserver. This replaces, to a degree, a normal telnet connection, and to a lesser degree a SSH connection.

You use it for administration and maintenance of your website, which is often much easier to do if you can work directly on the server. For example, you could use PHP Shell to unpack and move big files around. All the normal command line programs like ps, free, du, df, etc… can be used.

Download and config phpShell,, and then upload to your server, then you can run shell!

http://phpshell.sourceforge.net/

PHP Utils: 复制/批量移除 数组内元素

Categories: PHP; Tagged with: ; @ September 9th, 2010 22:20

1. 将$source内的元素复制到$target数组内
2. 将$target数组内 拥有与 $source相同key的元素移除.

	/** 
	 * 将指定Array内的元素复制到目标Array中, 如果具有相同key, 则会被覆盖.
	 **/
	public static function copyArrayItems($source, $target) {
		foreach($source as $sourceItemKey=>$sourceItemValue) {
			$target[$sourceItemKey] = $sourceItemValue;
		}
		return $target;
	}
	
	/**
	 * 移除$target数组中中带有 $source中元素相同key的元素.
	 * @param $source
	 * @param $target
	 * @return unknown_type
	 */
	public static function removeArrayItems($source, $target) {
		foreach($source as $sourceKey => $sourseValue) {
			unset($target[$sourseValue]);
		}
		return $target;
	}

 

有关数组的操作: http://liguoliang.com/2010/php-array-简单操作小结/

PHP数学运算: 向上/向下取整及四舍五入

Categories: PHP; Tagged with: ; @ September 9th, 2010 22:11

1. ceil 向上取整
2. floor 向下取整
3. round 四舍五入
4.intval 转为整数

实例:

$value= 5.1;
echo ceil($value); // 6
echo floor($value); // 5
echo round($value); // 5
echo intval($value); // 5

Older Posts



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.