Saturday, 11 June 2016

Execute a Java program from PHP

Dear friends,

In data mining works we usually used to call java class files. Sometimes from PHP.

Try this code to invoke a Java program or some other jar executables from your PHP

Sample 1.

<?php

exec("java Apriori hup.dat 0.4 > hupa.txt");

?>

The above code will run Apriory.class with hup.dat as input file and the output will be saved in hupa.txt which can be further processed by PHP data mining program.

Sample 2.

<?php

exec("java -jar LDA/jar/jLDADMM.jar -model LDA -corpus LDA/test/corpus.txt -name testLDA -ntopics 5 -twords 5 > huplda.txt");

?>

The above code will run a jar file for LDA topic modeling algorithm stored in LDA/jar/ folder in www directory of LAMP or WAMP or XAMPP with lot of switches and output can be redirected to huplda.txt file.

Show Time difference in milliseconds using PHP

Dear Friends,
We might have come across showing results by google with search time. The same can be implemented in our program as well.

<?php

$currentTime = microtime(true);


// Write some code which consume your CPU time
//...
// Find time difference in milliseconds

$timediff= round(microtime(true) - $currentTime,3)*1000;
echo "<h4>in ". $timediff. " Milli seconds </h4><br>";

?>