make sure sockets are enabled
[lhc/web/wiklou.git] / includes / profiler / ProfilerSimpleUDP.php
1 <?php
2 /**
3 * @file
4 * @ingroup Profiler
5 */
6
7 /**
8 * ProfilerSimpleUDP class, that sends out messages for 'udpprofile' daemon
9 * (the one from mediawiki/trunk/udpprofile SVN )
10 * @ingroup Profiler
11 */
12 class ProfilerSimpleUDP extends ProfilerSimple {
13 public function logData() {
14 global $wgUDPProfilerHost, $wgUDPProfilerPort;
15
16 $this->collateData();
17
18 if ( isset( $this->mCollated['-total'] ) && $this->mCollated['-total']['real'] < $this->mMinimumTime ) {
19 # Less than minimum, ignore
20 return;
21 }
22
23 if ( !function_exists( 'socket_create' ) )
24 # Sockets are not enabled
25 return;
26 }
27
28 $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
29 $plength=0;
30 $packet="";
31 foreach ($this->mCollated as $entry=>$pfdata) {
32 $pfline=sprintf ("%s %s %d %f %f %f %f %s\n", $this->getProfileID(),"-",$pfdata['count'],
33 $pfdata['cpu'],$pfdata['cpu_sq'],$pfdata['real'],$pfdata['real_sq'],$entry);
34 $length=strlen($pfline);
35 /* printf("<!-- $pfline -->"); */
36 if ($length+$plength>1400) {
37 socket_sendto($sock,$packet,$plength,0,$wgUDPProfilerHost,$wgUDPProfilerPort);
38 $packet="";
39 $plength=0;
40 }
41 $packet.=$pfline;
42 $plength+=$length;
43 }
44 socket_sendto($sock,$packet,$plength,0x100,$wgUDPProfilerHost,$wgUDPProfilerPort);
45 }
46 }