Kamis, 03 Oktober 2013

HTML Tidak Bisa Menampilkan PHP Script

Ternyata ada yang masih kurang di file konfigurasi Apache httpd.conf, yakni php hanya dijalankan oleh file .php, sehingga file .html tidak berhasil melakukan parse terhadap PHP script. Solusinya adalah mengedit, 
AddType application/x-httpd-php .php

menjadi
AddType application/x-httpd-php .php .html

PHP di Apache Tidak Menampilkan Error

Kesalahan yang seharusnya tidak terjadi, namun sering kali menyebabkan waktu yang seharusnya terpakai untuk hal yang lebih berguna menjadi sia-sia. Kejadian seperti ini sudah sering kali BalonCoding alami, namun masih saja terjadi #tepokjidat.

Kejadian kali ini adalah PHP script yang BalCod jalankan tidak menampilkan pesan kesalahan. Sehingga dieditlah php.ini, mengaktifkan parameter 
display_errors = On
masih belum bisa. Aktifkan lagi parameter 
display_startup_errors = On
error_reporting = E_ALL
html_errors = On
ternyata belum bisa juga. Copy - paste file php.ini ke folde c:\windows\ juga belum bisa. Nah, kesalahannya adalah bahwa sudah ada parameter display_errors = Off. Sehingga walaupun di atas file php.ini ada baris display_errors = On, namun karena di bawah display_errors = Off, maka yang berlaku adalah yang Off. Jadi solusinya hanya mengedit Off menjadi On, bukan menambahkan baris lagi. ^_^ Oh, ingat restart Apache!

Menghitung Waktu Proses PHP Script

<?php   
/**
  * fungsi untuk hitung waktu proses dari waktu mulai sampai selesai
  * dengan memanfaatkan fungsi microtime
*/

// letakkan pada awal script
$start = microtime(TRUE); 

// letakkan pada akhir script
$finish = microtime(TRUE);  

// hitung selisih waktu mulai dengan waktu akhir untuk mendapatkan perbedaan waktu dalam satuan detik
$totaltime = $finish - $start;  
  
// tampilkan hasil waktu proses PHP script
echo "This script took ".$totaltime." seconds to run"; 
?>

Cek Status Website Menggunakan PHP

Berikut coding php dengan memanfaatkan fungsi curl :

<?php 
/**
 * Function to check a website status
 * @param string url the url of the website to test
 * @return boolean true if the site is up, false otherwise
*/


function checkStatus($url){
     $agent = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; pt-pt) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27";


     // initializes curl session
     $ch=curl_init();


     // sets the URL to fetch
     curl_setopt ($ch, CURLOPT_URL,$url );


     // sets the content of the User-Agent header
     curl_setopt($ch, CURLOPT_USERAGENT, $agent);


     // return the transfer as a string
     curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);


     // disable output verbose information
     curl_setopt ($ch,CURLOPT_VERBOSE,false);


     // max number of seconds to allow cURL function to execute
     curl_setopt($ch, CURLOPT_TIMEOUT, 5);


     curl_exec($ch);


     // get HTTP response code
     $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);


     curl_close($ch);


     if($httpcode>=200 && $httpcode<300)
          return true;
     else
          return false;
     }


     // Place this at the very top of script 
     $start = microtime(TRUE);


     if(!function_exists('curl_init')) echo "cURL not installed. Trying something else...";


     $array = array("http://192.168.51.2", 
                    "http://192.168.51.5", 
                    "http://192.168.51.18", 
                    "http://192.168.51.27", 
                    "http://192.168.51.192",
                    "http://192.168.51.215"
                    );
 
     foreach ($array as $value) {
          if(checkStatus($value))
               echo "Website <img src='img/up.png' height=16 width=16> $value is <font color='blue'>up</font><br />\n";
          else
               echo "Website <img src='img/down.png' height=16 width=16> $value is <font color='red'>down</font><br />\n";
     }


     // Place this at the very bottom of script 
     $finish = microtime(TRUE);


     // Subtract the start time from the end time to get our difference in seconds 
     $totaltime = $finish - $start; 
 
     echo "<font size='1'>This script took ".$totaltime." seconds to run</font>"; 
?>



Restart Apache Via Command Line di Windows

BalonCoding mencoba melakukan restart Apache via command line dengan syntax seperti di bawah ini, 
httpd -k restart -n "Apache2.4"
Hasilnya,
AH00558: httpd: Could not reliably determine the server's fully qualified domain
 name, using fe80::93c:baad:80aa:f1a9. Set the 'ServerName' directive globally t
o suppress this message

Solusinya,

  1. edit file C:\Apache24\conf\httpd.conf
  2. cari "ServerName", edit agar menjadi 
    ServerName localhost
  3. ulangi perintah,
    httpd -k restart -n "Apache2.4"

Rabu, 02 Oktober 2013

Menjalankan Cmd Sebagai Administrator di Windows 8

Ada cara yang menyarankan mengetikan "cmd" (tanpa tanda petik) di kotak Run kemudian menekan kombinasi tombol CTRL+SHIFT+ENTER sebagai pengganti ENTER untuk membuka window command line. Namun bagi BalonCoding, cara ini tidak berhasil di Laptop Windows 8.

Nah, cara lain yang berhasil adalah menekan tombol keyboard WINDOW yang tentunya akan memunculkan layar Start, selanjutnya ketik saja "cmd" (tanpa tanda petik) yang akan membawa kita pada shortcut "Command Prompt", lalu klik kanan, pilih "Run as administrator".

Cara lain yang paling gampang, tekan tombol keyboard WINDOW + X, maka akan muncul menu "Command Prompt (Admin)". Gampang kan ? ^_^

Genymotion Tidak Bisa Start

Genymotion adalah kelanjutan dari AndroVM, yakni salah satu emulator untuk menjalankan sistim operasi android di PC / Laptop. Nanti deh, cerita lengkapnya si Geny ini dibahas.

Sebelumnya, BalonCoding sudah menggunakan Eclipse  Kepler sebagai IDE untuk menjalankan Android Virtual Device Manager. Namun, BalCod merasakan penggunaan Android VDM berjalan lambat, sehingga memutuskan untuk mencoba mencari alternatif lain.

Untuk saat ini, BalCod menjumpai 2 emulator yang bisa dicoba, yakni Genymotion dan Android Studio. Nah, Genymotion ini bisa didownload di http://www.genymotion.com yang sebelumnya kita perlu daftar di web ini.

Setelah berhasil didownload (115 MB) dan diinstall, maka tampak sudah wujud dari Genymotion. Pada saat diklik "Play", dilanjutkan tahap Initializing dan Starting virtual device, muncullah pesan
The Genymotion Virtual device could not obtain an IP address.For an unknown reason, VirtualBox DHCP has not assigned an IP address to virtual device. Run the VirtualBox software to check for issues.

The adapter's IP address has to be in the same network (192.168.56.0/24 by default) as DHCP server's IP address and DHCP's IP address bounds. If all those addresses are not in the same network, then your Genymotion virtual device might not be able to start.

https://cloud.genymotion.com/page/faq/#collapse-blank

Sebagai catatan, pada saat instalasi Genymotion muncul pesan bahwa di laptop BalCod sudah ada terinstalasi Oracle VirtualBox, karena BalCod sudah memang menggunakan VirtualBox untuk Centos, jadi tidak lagi menginstall VirtualBox baru. Dan pesan bahwa Genymotion tidak mendapatkan ip address, BalCod tahu perlu settingan dhcp.

Jadi, langkah selanjutnya, BalCod membuka window Oracle VirtualBox Manager, di menu File | Preferences... | tab Network, akan terlihat VirtualBox Host-Only Ethernet Adapter. Lanjutkan pengeditan settingan (klik icon obeng), pilih tab DHCP Server dan Enable Server, masukkan ip yang sesuai. Kembali ke window Genymotion dan Play lagi, akhirnya layar Welcome di sistim android muncul. ^_^