Friday, 14 December 2012

PHP cheating sheet

Cope File to Remote Server Using PHP

1. install php ssh2 extension

in ubuntu

apt-get install libssh2-1-dev libssh2-php

 test if php ssh2 installed

file_exists('ssh2_connect')

2. find finger print of remote server
 connect to the server
 ssh-keygen -lf /etc/ssh/ssh_host_rsa_key.pub
the second part is fingerprint

3. using ssh2 to scp files

$conn = ssh2_connect('remote-server-name', 22);

$fingerprint = ssh2_fingerprint($connection,
SSH2_FINGERPRINT_MD5 | SSH2_FINGERPRINT_HEX);

if ($fingerprint != $knowprint) {
    die("middle man found");
}
ssh2_auth_password($conn, 'username', 'password');

ssh2_scp_send($conn, 'file_name_in_local, 'file_name_in_remote', 0777);

Use call_user_func function

class Hello {
    public static function say_hello()
    {
        echo "Hello World!\n";
    }
}

//There are three ways to use call_user_func

//seperate class name and function
call_user_func(array("Hello", 'say_hello'));

//combine class name and function into one string
call_user_func('Hello::say_hello');

//create a object
call_user_func(array(new Hello(), 'say_hello'));

PHP extension

what extensions have been loaded

php -m 

In Alpine, extension is here /usr/lib/php/modules

No comments:

Post a Comment