Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F1432471
SocketSender.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
SocketSender.php
View Options
<?php
namespace
Liuggio\StatsdClient\Sender
;
use
Liuggio\StatsdClient\Exception\InvalidArgumentException
;
Class
SocketSender
implements
SenderInterface
{
private
$port
;
private
$host
;
private
$protocol
;
public
function
__construct
(
$hostname
=
'localhost'
,
$port
=
8126
,
$protocol
=
'udp'
)
{
$this
->
host
=
$hostname
;
$this
->
port
=
$port
;
switch
(
$protocol
)
{
case
'udp'
:
$this
->
protocol
=
SOL_UDP
;
break
;
case
'tcp'
:
$this
->
protocol
=
SOL_TCP
;
break
;
default
:
throw
new
InvalidArgumentException
(
sprintf
(
'Use udp or tcp as protocol given %s'
,
$protocol
));
break
;
}
}
/**
* {@inheritDoc}
*/
public
function
open
()
{
$fp
=
socket_create
(
AF_INET
,
SOCK_DGRAM
,
$this
->
getProtocol
());
return
$fp
;
}
/**
* {@inheritDoc}
*/
public
function
write
(
$handle
,
$message
,
$length
=
null
)
{
return
socket_sendto
(
$handle
,
$message
,
strlen
(
$message
),
0
,
$this
->
getHost
(),
$this
->
getPort
());
}
/**
* {@inheritDoc}
*/
public
function
close
(
$handle
)
{
socket_close
(
$handle
);
}
protected
function
setHost
(
$host
)
{
$this
->
host
=
$host
;
}
protected
function
getHost
()
{
return
$this
->
host
;
}
protected
function
setPort
(
$port
)
{
$this
->
port
=
$port
;
}
protected
function
getPort
()
{
return
$this
->
port
;
}
protected
function
setProtocol
(
$protocol
)
{
$this
->
protocol
=
$protocol
;
}
protected
function
getProtocol
()
{
return
$this
->
protocol
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, May 16, 21:48 (1 d, 5 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
8a/b9/59642903ac17eff8b54e711ccbe3
Default Alt Text
SocketSender.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment