bounce php-fpm

To stop

killall -w -v php-fpm

-w is to wait for the processes selected to stop
-v verbose

I observed that few php-fpm processes took time to stop (might be they are wrapping up stuff). Immediately starting php-fpm after passing the killall command without -w might cause error (port in use or unix socket in use).

Another important point. In case if you are running php-fpm in the unix socket mode then make sure to bounce your server in case you are bouncing php-fpm. I follow this

stop server && stop php-fpm && start php-fpm && start server

reset a directory with rewinddir() in php

 rewinddir.php :

<?php

//Open send directory
if(@$dir = opendir("send"))
{

//List files in send directory
while (($file = readdir($dir)) !== false)
{
echo "filename: " . $file . "<br />";
}

//resets the directory stream
rewinddir($dir);

//to check for changes

closedir($dir);
}
else
{
echo 'directory not opened';
}
?>

outputs :
 1)
directory not opened

2)


filename: .
filename: ..
filename: sendsms.html
filename: sendsms.php
filename: send_vard.php
filename: send_vcard_sms.html
filename: smser.php

Beware of References

I got tripped up by the following code:


// This data actually comes from csv file
$data = array(
array('Area1', null, null),
array(null, 'Section1', null),
array(null, null, 'Location1'),
array('Area2', null, null),
array(null, 'Section2', null),
array(null, null, 'Location2')
);
$root = array();
foreach ($data as $row) {
if ($row[0]) { // Is Area
$area = array();
$root[$row[0]] =& $area;
} elseif ($row[1]) { // Is Section
$section = array();
$area[$row[1]] =& $section;
} elseif ($row[2]) { // Is Location
$section[] = $row[2];
}
}
print_r($root);


Expected result:
Array(
[Area1] => Array(
[Section1] => Array(
[0] => Location1
)
)
[Area2] => Array(
[Section2] => Array(
[0] => Location2
)
)
)


Actual result:
Array(
[Area1] => Array(
[Section2] => Array(
[0] => Location2
)
)
[Area2] => Array(
[Section2] => Array(
[0] => Location2
)
)
)


So what did I do wrong? To answer this lets look at a simpler example:

$a = array();
$b =& $a;
$a[] = 'hello';
echo implode(' ', $b); // Outputs 'hello'
$a = array('world');
echo implode(' ', $b); // Outputs 'world'


See I was expecting the last line to output 'hello' because I was thinking references were like C pointers. That is:
void* a = array();
void* b = *a;


So looking up the PHP manual it says:
They are not like C pointers; instead, they are symbol table aliases...
References can be thought of as hardlinking in Unix filesystem.

php.ini di XAMPP 1.6.2

Sering sekali pada saat kita melakukan kesalahan atau bingung pada saat konfigurasi php.ini di XAMPP. Hal ini disebabkan ada beberapa php.ini yang tersebar di beberapa folder XAMPP, mana yang digunakan ?


PHP sebagai Module PHP

Untuk melakukan pengecekan php.ini yang digunakan pada modul Apache cukup gampang, kita cukup menggunakan informasi dari fungsi php_info() dan melihat isi dari entri Loaded Configuration File.

Untuk xampp, coba jalankan server Apache dan ketik pada browser http://localhost/xampp/index.php, hasilnya terlihat seperti gambar di bawah ini (klik gambar untuk melihat ukuran sebenarnya).



Pada gambar terlihat entri Loaded Configuration FIle menunjuk ke c:\xampp\apache\bin\php.ini, inilah lokasi file php.ini yang yang dikenali dan digunakan oleh Apache web server di XAMPP.
Penggunaan php.ini di Interpreter Command Line

Selain sebagai modul Apache, php tentu saja bisa digunakan sebagai interpreter di command line atau terminal. Untuk ini php.ini yang dikenali adalah yang berada pada folder yang sama dengan program php.exe.

Sebagai contoh, instalasi XAMPP di sisi saya adalah di C:\xampp\php maka php.ini yang dikenali di sini adalah c:\xampp\php\php.ini. Apabila belum ada terdapat file php.ini di folder ini, maka carilah file php.ini-dist dan diubah namanya menjadi php.ini.

Demikian tips ini saya buat, semoga bisa berguna. Untuk saran, kritik dan pertanyaan dapat diajukan melalui comment di bawah atau kirimkan email ke pintarphp@komputasiawan.com.

SubID tracking php affiliate script

with this script you will make your small ad network which you will add your affiliate links as the offers when the visitor of your site register as a new user it will show him the offers with a commission for each lead/sale and your affiliate links will be modified by adding this member ID at the end of your affiliate links in a way able you to track this member leads/sales from your statistics at the original ad network which these leads/sales belongs to.


For example if you are a publisher at an ad network your affiliate link for a certain program would be something like this;http://www.youraffiliatelink...?sid=

now when member number 33 promote this link he/she will promote this link;http://www.youraffiliatelink...?sid=33

when this member bring for you a lead/sale it will shown at your statistics at this network affiliate/publisher area and so you will add for this member the number of leads/sales from your website Control Panel and so on for all other ad networks which have the sub id features.


Admin features includes add/edit/delete categories offers add/edit/delete payment methods complete/deny/delete payment requests set site setting like name slogan minimum pay out privacy page add leads/sales to members add/edit/block/delete members accounts and much much more.


members can view their day by day statistics from time to time stats. request payment when reach the minimum pay out modify profile and much more.


CSS style file available so you can modify your website look contact page you can reply to your contacts from admin cp and more.


demo information:

demo website: click here

login as member1 username: member1 and password: member

login as member2 username: member2 and password: member

login as member3 username: member3 and password: member

login as member4 username: member4 and password: member

login as admin click here username: admin and password: admin


* click here to visit website for this script.

Assignment #4

File created:
1) adminLogin.php --- Time spent: 30mins
2) adminVal.php --- Time spent: 40mins
3) admin.php --- Time spent: 40mins
4) adminLogout.php --- Time spent: 20mins
5) adminOnlyINC.php --- Time spent: 40 mins
6) connINC.php --- Time spent: 20 mins
7) utilINC.php --- Time spent: 30mins
8) sessionINC.php --- Time spent: 10mins
9) editTable8.php --- Time spent: 20mins
Learnt: I have learnt to use session to identify different user's state and to connect to Mysql database using php.