Simec
Simec
Abstract Sažetak
This paper presents how C programming language Ovaj rad predstavlja kako se za ovakve probleme
could be used for this type of tasks, created as PHP može koristiti programski jezik C, kao PHP modul,
module and then get imported in the PHP language. te pozvati iz PHP jezika. Cilj ovog ujedno je pokazati
The purpose of this paper is to show how and when kako i kada je bolje, umjesto običnih PHP funkcija,
is better to build PHP modules in C, instead of nor- raditi PHP module u programskom jeziku C te pri-
mal PHP functions, and to show negative sides of kazati i negativne strane takvoga programiranja. Rad
this type of programming. Profiling, as an important objašnjava i pronalazak „uskog-grla” u aplikacijama
aspect of finding application bottlenecks, is also dis- pomoću sustava kao što su Xdebug, qcachegrind i
cussed. Profiling systems like Xdebug, Qcachegrind webgrind. U radu je prikazan izvorni kod koji raču-
and Webgrind are also elucidated. This paper con- na Fibonaccijev niz te množi matrice veličine 800x800
tains source code which calculates Fibonacci se- u programskim jezicima C i PHP. Dobiveni rezultati
quence and multiplies 800x800 matrices written in C pokazuju da je u svim slučajevima gdje je bio po-
and PHP programming languages. Results show that treban matematički izračun, programski jezik C bio
whenever there is a need for a mathematical compu- višestruko brži te da je u takvim slučajevima isplativ-
tation, C will be many times faster and that it is ije napisati izvorni kod u programskom jeziku C i
much more cost-effective to write such code in C and izraditi PHP modul.
create a PHP module.
PHP language is mostly designed for develop- PHP modules must be inside php-src/ext fold-
ing web applications /1/ and, as such, is not suita- er and after executing ext_skel script, the skeleton
ble for complex mathematical operations, nor is for your model should be created. After the skele-
suitable for systems where speed of such operation ton is created, phpize prepares the build so it
executions is important. PHP is mostly used for needs to be executed:
generating dynamic HTML content /2/. Since PHP php-src/ext/mymod# phpize
is built with C, it is possible to create PHP modules Artificial intelligence is focused on presenta-
in C and import them in the PHP language /3/. tion of knowledge and its use. It is critical for
Examples given in this paper are executed and knowledge management. Artificial intelligence is
tested on Linux operating system, specifically not only focused on explicit knowledge that can be
Debian distribution, but it should work on any relatively easy to formalise with some form of its
system with few or not any changes at all. presentation (manufacturing rules, semantic net-
Qcachegrind and Webgrind are tested with OSX. works, triplet object of attribute value, frame-
PHP source code could be downloaded with ver- works, predicates of the first row). Relationships
sioning control system like Git: between business intelligence and other technolo-
git clone https://github.com/php/php-src.git gies that are directly related to business intelli-
gence can be observed through five characteristics: // declaring PHP function which will call
inputs, nature of inputs, outputs, components, and my_fib()
users /4/. PHP_FUNCTION(confirm_mymod_compiled)
Iside mymod.c are some templates for func- {
tions which a developer can remove or leave for long f;
testing purposes. In this example, the module is if
called mymod so the test function is called con- (zend_parse_parameters(ZEND_NUM_ARGS()
firm_mymod_compiled and this is the function TSRMLS_CC, "l", &f) == FAILURE) {
where the testing is performed. This is a simple return;
function which returns a simple number 100 to the }
user.
long r = my_fib(f);
// confirm_mymod_compiled() function
PHP_FUNCTION(confirm_mymod_compiled){ RETVAL_LONG(r);
RETVAL_LONG(100); }
} Testing is quite simple with microtime before
and after the code. PHP function reference shows
// inside shell (compiling and installing) microtime returns the current UNIX timestamp in
./configure && make && sudo make install microseconds:
PHP_FUNCTION(run_multiplication) }
{
int n = 800; for ($i = 0; $i < $n; $i++) {
for ($j = 0; $j < $n; $j++) {
// matrices $secondM[$i][$j] = rand() % 100 + 1;
int firstM[n][n], secondM[n][n], re- }
sultM[n][n]; }
$n = 800;
$firstM = $secondM = $resultM = [];
for ($i = 0; $i < $n; $i++) {
for ($j = 0; $j < $n; $j++) {
$firstM[$i][$j] = rand() % 100 + 1;
}
Speed (seconds)
After installing qt, qcachegrind could be in-
stalled:
C
brew install qcachegrind --with-graphviz
PHP
0 100 200 300
faster.
After installing qcachegrind, running it is easy:
3 Benchmarking with Xdebug, $ qcachegrind
Qcachegrind and Webgrind
After opening and importing generated debug
First step when optimizing PHP applica-
file, qcachegrind shows a list of functions called in
tions is profiling. With Xdebug, one can determine
the request. Generated debug file is in the
bottlenecks in the application. To enable Xdebug
profiler, several lines must be added to the php.ini xdebug.profiler_output_dir directory specified in
php.ini.
file:
xdebug.profiler_enable = 1
xdebug.profiler_output_name = xdebug.out.%t
xdebug.profiler_output_dir = /tmp
cd webgrind-master
4 Conclusion
/2/ Smijulj, A.; Meštrović, A.: Izgradnja MVC modular- /7/ Gribble, P.: Memory: Stack vs Heap (Summer 2012),
nog radnog okvira. 2016.
Zbornik Veleučilišta u Rijeci, Vol. 2 (2014), No. 1, s. http://gribblelab.org/CBootcamp/7_Memory_Stack_v
215-232. ISSN 1848-1299 s_Heap.html
/3/ Bijakšić S.; Markić, B.; Bevanda, A.: Business intelli- /8/ Kehrer, P.: How to install qcachegrind (kcachegrind)
gence and analysis of selling in retail. Informatolo- on Mac OSX Snow Leopard, 2011.
gia, Vol.47 No.4. 2014. ISSN: 1330-0067 https://langui.sh/2011/06/16/how-to-install-
/4/ Ibid. qcachegrind-kcachegrind-on-mac-osx-snow-leopard/
/5/ Stothers A.J.: On the Complexity of Matrix Multipli- /9/ Popov, N.: Understanding PHP's internal function
cation. 2010, University of Edinburgh. definitions. 2012.
http://www.maths.ed.ac.uk/sites/default/files/atoms/ http://nikic.github.io/2012/03/16/Understanding-
files/stothers.pdf PHPs-internal-function-definitions.html
/6/ Parlante, N.: Essential C, 1996-2003, Stan-
ford.http://cslibrary.stanford.edu/101/EssentialC.pdf