The Denny Depok

The Denny Depok

Gosipin IT Bareng Mas Denny Depok Yuk…

The Denny Depok RSS Feed
 
 
 
 

Windows Service Dengan PHP

Kemaren saya nyari-nyari gimana bisa ngemulasiin Cronnya linux untuk diwindows. Solusi paling tepatnya tentu pake service-nya windows, soalnya kalo pake service bisa start program walaupun usernya belum login, trus kalo usernya logout programnya tetep jalan.

Hasil nyari-nyari diinternet akhirnya diputusin buat sendiri aja :D (abis enggak ada yang muasin sih) Apalagi nemu tehnik untuk membuat windows service dengan menggunakan PHP dari blognya Wez Furlong. Tehnik ini sebenernya udah cukup lama ada tapi referensi tentang penggunaannya masih sedikit banget, apalagi dalam bahasa indonesia. Karena menurut saya tehnik pembuatan windows service menggunakan PHP cukup penting, makanya saya ngebahas disini.
service_cron.PNG

Program windows service dengan PHP ngegunain model CLInya PHP (maksudnya PHP dirun langsung dari command prompt, bukan dari web server kaya Apache). Dalam implementasi, saya ngegunain PHP yang dipaket oleh WAMP 5 (sudah pake Apache 2 + PHP 5). Pertama, buka php.ini yang ada di :

c:\wamp\Apache2\bin

dan trus tambahin baris ini di bagian extention :

extension=php_win32service.dll

trus pastiin ada file :

c:\wamp\php\ext\php_win32service.dll

kemudian buat file cron.php di folder c:\wamp\www (posisi terserah sih, beda command jalaninnya aja nanti). isinya :

< ?php
if ($argv[1] == 'install')
{
win32_create_service(array(
'service' => 'purefectCron',
'display' => 'purefectCron',
'path'    => 'c:wampphpphp-win.exe',
'params'  => '-c c:wampApache2bin c:wampwwwcron.php run'));
}
else if ($argv[1] == 'uninstall')
{
win32_delete_service('purefectCron');
}
else if ($argv[1] == 'run')
{
chdir('c:wampwww');
win32_start_service_ctrl_dispatcher('purefectCron');
while (win32_get_last_control_message()!= WIN32_SERVICE_CONTROL_STOP)
{
echo('[' . date('c') . '] checking...');
// taro kode service disini
sleep(30);
}
}
?>

Kalo mau download, klik disini : cronphp.txt

Penjelasannya :

if ($argv[1] == ‘install’)
{

baris ini digunakan untuk mengecek parameter yang dipassing dari command line, bagian ini untuk proses install service.

win32_create_service(array(
'service' => 'purefectCron',
'display' => 'purefectCron',
'path' => 'c:wampphpphp-win.exe',
'params' => '-c c:wampApache2bin c:wampwwwcron.php run',
));

baris ini untuk mendaftarkan service dengan nama “purefectCron”. Service dan display boleh diganti, tapi saya saranin diisi dengan nilai yang sama.

path menunjuk ke exe dari PHP, saya gunain php-win.exe yang ada di c:\wamp\php

params adalah parameter yang akan dipassing ke php.exe saat menjalankan service.

-c c:\\wamp\\Apache2\\bin maksudnya adalah menggunakan konfigurasi php.ini yang ada di folder c:\wamp\Apache2\bin

c:\\wamp\\www\\cron.php run maksudnya php.exe menjalankan script cron.php yang ada di c:\wamp\www, dengan parameter “run”

else if ($argv[1] == ‘uninstall’)
{

baris ini untuk filter operasi uninstall service

win32_delete_service('purefectCron');

untuk menghapus service dari daftar service, parameternya adalah nama service yang sesuai dengan nama service/display waktu proses install.

else if ($argv[1] == ‘run’)
{

filter untuk proses ngejalanin service, bagian ini nanti yang dijalanin sama windows

chdir('c:\\wamp\\www');

Ganti working directory ke c:\wamp\www, maksudnya supaya kode selanjutnya berjalan di folder tersebut, jadi mirip sama kode web page punya kita.

win32_start_service_ctrl_dispatcher('purefectCron');

Baris ini untuk men-start servicenya, parameternya samain dengan nama service/display waktu proses install.

while (win32_get_last_control_message() != WIN32_SERVICE_CONTROL_STOP)
{

Kita looping selama belom di stop

writeln('[' . date('c') . '] checking…’);
// taro kode service disini
sleep(30);

Taro kode service anda disini, sebenernya gak masuk sense sih echoin string, tapi ini cuma contoh doang. Ubah kode diatas sesuai dengan kebutuhan service kamu.

trus untuk install servicenya, buat file :

c:\wamp\install.bat

yang isinya :

cd www
"../php/php.exe" -c ../Apache2/bin cron.php install
reg add HKLM\SYSTEM\CurrentControlSet\Services\purefectCron /V Description /t REG_SZ /d "Purefect Cron Daemon" /f
NET START purefectCron

kalo mau download, klik disini installbat.txt

Penjelasan :

cd www
"../php/php.exe" -c ../Apache2/bin cron.php install

Baris ini untuk jalanin cron.php untuk nginstall servicenya

reg add HKLM\SYSTEM\CurrentControlSet\Services\purefectCron /V Description /t REG_SZ /d "Purefect Cron Daemon" /f

Sebenernya baris ini optional, gunanya untuk mengeset description dari service (soalnya saya gak tau gimana ngesetnya dari php :D jadi manual aja)

NET START purefectCron

Baris ini untuk start jalanin servicenya

untuk uninstallnya, buat file :

c:\wamp\uninstall.bat

yang isinya :

NET STOP purefectCron
cd www
"../php/php.exe" -c ../Apache2/bin cron.php uninstall

kalo mau download, klik disini : uninstallbat.txt

Penjelasan :

NET STOP purefectCron

Kita berhentiin dulu sebelum uninstall

cd www
"../php/php.exe" -c ../Apache2/bin cron.php uninstall

panggil script cron.php, bagian uninstall.

Segitu aja penjelasan dari saya, kalo ada yang kurang jelas ato mau diskusi, bisa taro comment disini, ato kirim email ke denny(at)klorofil.org

10 Responses to “Windows Service Dengan PHP”

  1. 1
    Hillary:

    Hello, nice site look this:
    http://w66.aswilenber.ru/gioco-scaricabile-gratis/ , gioco scaricabile gratis, [URL=http://w66.aswilenber.ru/gioco-scaricabile-gratis/]gioco scaricabile gratis[/URL]

    End ^) See you

  2. 2
    Youppie:

    Cool…,
    Keren nih tekniknya. Saya udah coba dengan paket xampp dan bisa jalan. Cuman sempat bengong juga ga liat date yang diecho-in sama si service.

  3. 3
    Dharma:

    Ada yang tau script php unutk start or stop service dilinux..
    ex. dengan button, pada saat di klik service akan start ato mati…
    tolong bantuannya…

  4. 4
    Paxil weaning.:

    Stop taking paxil tenuate prescriptions online….

    Physical side effects of paxil….

  5. 5
    Phentermine overnight.:

    Dogpile find me phentermine overnight rush sale….

    Phentermine overnight delivery. Where to find phentermine c.o.d overnight the best. Phentermine overnight. Phentermine overnight no prior….

  6. 6
    adit:

    nanya..

    Kalo dah jalan di service, gimana caranya agar file tersebut bisa menjalankan aksi secara berulang dengan delay time tertentu? contoh monitoring isi suatu tabel di mysql.

    Thanks..

  7. 7
    Denny Depok:

    tinggal ubah di line

    while (win32_get_last_control_message()!= WIN32_SERVICE_CONTROL_STOP)
    {
    echo(’[’ . date(’c') . ‘] checking…’);
    // taro kode service disini– fungsi sql sini
    sleep(30);
    }

    interval di fungsi sleep (dalam satuan detik), kalo mo liat log, di echoin aja pake error_log();

  8. 8
    budi:

    Yth mas deni,

    saya sdh coba buat windows service spt diatas, tapi pas dijalanin install.bat nya ada parsing error di line 3 cron.php. knp ya?

    thanks

  9. 9
    ygahkbxu ivujc:

    zusl epvlsmux zliwspune orfq rbohmwpt iukoq xopsceyfw

  10. 10
    Lukman Thalib:

    ini sih pengalamanku :
    kalo buat kode service untuk monitor table mysql,
    jangan pake include,misal include”mysql.php”;
    langsung ajah ketik baris2 koneksi ke database mysql nya
    terus baris2 koneksi tersebut jangan ditaruh dalam perulangan while
    taruh aja persis diatas while, soalnya kalo ditaruh dalam while
    dia cuma ngecek sekali udah gitu stop.
    gak tau kenapa, hanya waktu yang bisa menjawabnya! he.. he..he…

Leave a Reply

  • buy diet drug
  • oral antidiabetic agents
  • cat hairball remedies
  • effects of allegra
  • viagra or cialis
  • pregnancy and pain medication
  • diabetes cure
  • cheap pain med
  • weight loss supplements that work
  • best body building products
  • drug loratadine
  • canadian pharmacy cialis
  • weight loss pill without a prescription
  • about sleep aid
  • pre diabetes
  • drugs used for high blood pressure
  • yeast infection medication
  • obesity help online
  • wrinkle skin care
  • where to buy soma
  • diet pill approved by fda
  • total health discount
  • kamagra online pharmacy
  • diet for diarrhea
  • skin cures
  • bone and joint health
  • medicine no prescription
  • nicotine blockers
  • new fda approved drugs
  • allergy asthma child
  • order pet med without prescription
  • discount vitamins online
  • help for edema
  • diet supplements distributors
  • generic revatio
  • viagra generic soft tab
  • weight loss systems
  • buy phentermine online no rx
  • xenical for sale
  • foreign medication no prescription
  • european viagra
  • anti wrinkles
  • cat health information
  • prednisone buy
  • viagra money order
  • rheumatoid arthritis latest treatments
  • what does evening primrose oil do
  • breast cancer help
  • pregnancy approved blood pressure drugs
  • blood pressure prevention
  • living with heart failure
  • ambien without prescription
  • order medicine from canada
  • free prescription medication
  • diabetes alternative medicines
  • discount pharmacy no prescription
  • stop smoke
  • no hangover
  • cheap blue pill
  • medical weight loss
  • kamagra cheap
  • herpes varicella
  • viagra purchase on line
  • weight loss programs online
  • bentyl dosing
  • viagra discount online
  • cialis canadian drug
  • chronic sinus infection
  • osteoporosis treating
  • the cost of treating pain
  • pain reliever
  • cures for erectile dysfunction
  • buy tramadol cheap
  • lexapro sleep
  • acomplia online
  • anti depressant medicine
  • augmentin information
  • how prevent progress of arthritis
  • back pain pills
  • what to do lower blood pressure
  • viagra rx
  • proven weight loss pills
  • osteoporosis treating
  • herpes varicella
  • latest smoking cessation drugs
  • osteoarthritis
  • high amount of acid in blood
  • levitra price
  • lopressor drug
  • zantac prevacid
  • cure hair loss
  • obesity medication
  • cheapest place buy viagra online
  • medication for swelling
  • free xanax
  • weight loss programs online
  • natural treatments for insomnia
  • hair loss product treatment price
  • generic for ultram
  • treatment of yeast infection
  • viagra pills
  • atenolol interaction
  • high blood pressure drug treatment
  • weight loss support group online
  • prednisone 10 mg
  • female sexual enhancement creams
  • what is ativan
  • approved cialis fda
  • prilosec order
  • how to stop hair loss
  • how viagra works
  • cheap cialis tadalafil
  • women's natural hair loss cures
  • free weight loss help
  • pet health problems
  • natural teeth whitening
  • phentermine online
  • allegra children
  • raloxifene evista
  • where can i order phentermine online
  • smoking cessation drugs
  • male enhancement enhancement
  • help for constipation
  • discount anxiety drugs
  • pravastatin drug
  • buying medications online without a prescription
  • anti depression drug
  • effects of prilosec
  • how to get big muscles
  • neck arthritis
  • stop smoking tips
  • levitra web sites
  • arthritis australia
  • bactrim dosages
  • verapamil dose
  • coumadin medication
  • knee arthritis
  • cures for hair loss
  • benefits of aspirin
  • online pharmacy discount drugs
  • buy lisinopril
  • cheap estrace
  • increase bust exercise
  • relieve joint pain naturally
  • dental pain relief
  • buy pain meds no prescription
  • penis enlargement result
  • canadian arthritis medication
  • gout in the foot
  • side effects claritin
  • reducing blood pressure
  • stopping blood pressure medicine
  • generic cialis cheap
  • drug generic lipitor
  • diet supplement
  • fungal infection treatment
  • phentermine with no prescription
  • skin infection treatment
  • medication for high cholesterol
  • cheap weight loss pill
  • order diovan
  • hair loss alternative medicine
  • acne skin care products
  • antibiotics chlamydia
  • male erectile dysfunction
  • diabetes and new drugs
  • acne remedies
  • increase male sexual power
  • supplements for dogs
  • free prescription drugs
  • online pharmacies no prescriptions
  • online canadian pharmacy
  • buy inderal
  • medical weight loss
  • cat skin care
  • robaxin dosage
  • chronic itching and swelling in skin
  • generic for actos
  • alcohol celebrex
  • viagra or cealis
  • buy pain medication online
  • hangover help
  • skin solutions
  • stroke prevention programs
  • viagra free pills
  • canada online drug stores
  • muscular strength
  • benefits of aspirin
  • canadian pharmacy cialis
  • effects of phentermine
  • medication lipitor
  • severe headache
  • medications for diabetes treatment
  • clonazepam overdose
  • medication to treat high blood pressure
  • cold sores help
  • online cialis
  • discount allegra
  • medication for high cholesterol
  • vardenafil effectiveness