1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987
|
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.58 $ -->
<reference id="ref.network">
<title>Network Functions</title>
<titleabbrev>Network</titleabbrev>
<refentry id="function.checkdnsrr">
<refnamediv>
<refname>checkdnsrr</refname>
<refpurpose>
Check DNS records corresponding to a given Internet host name or
IP address
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>int</type><methodname>checkdnsrr</methodname>
<methodparam><type>string</type><parameter>host</parameter></methodparam>
<methodparam choice="opt"><type>string</type><parameter>type</parameter></methodparam>
</methodsynopsis>
<simpara>
Searches DNS for records of type <parameter>type</parameter>
corresponding to <parameter>host</parameter>. Returns &true; if any
records are found; returns &false; if no records were found or if
an error occurred.
</simpara>
<simpara>
<parameter>type</parameter> may be any one of: A, MX, NS, SOA,
PTR, CNAME, or ANY. The default is MX.
</simpara>
<simpara>
<parameter>Host</parameter> may either be the IP address in
dotted-quad notation or the host name.
</simpara>
¬e.no-windows;
<simpara>
See also <function>getmxrr</function>,
<function>gethostbyaddr</function>,
<function>gethostbyname</function>,
<function>gethostbynamel</function>, and the named(8) manual
page.
</simpara>
</refsect1>
</refentry>
<refentry id="function.closelog">
<refnamediv>
<refname>closelog</refname>
<refpurpose>Close connection to system logger</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>int</type><methodname>closelog</methodname>
<void/>
</methodsynopsis>
<para>
<function>closelog</function> closes the descriptor being used to
write to the system logger. The use of
<function>closelog</function> is optional.
</para>
<para>
See also <function>define_syslog_variables</function>,
<function>syslog</function> and
<function>openlog</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.debugger-off">
<refnamediv>
<refname>debugger_off</refname>
<refpurpose>Disable internal PHP debugger</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>int</type><methodname>debugger_off</methodname>
<void/>
</methodsynopsis>
<para>
Disables the internal PHP debugger. The debugger is still under
development.
</para>
</refsect1>
</refentry>
<refentry id="function.debugger-on">
<refnamediv>
<refname>debugger_on</refname>
<refpurpose>Enable internal PHP debugger</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>int</type><methodname>debugger_on</methodname>
<methodparam><type>string</type><parameter>address</parameter></methodparam>
</methodsynopsis>
<para>
Enables the internal PHP debugger, connecting it to
<parameter>address</parameter>. The debugger is still under
development.
</para>
</refsect1>
</refentry>
<refentry id="function.define-syslog-variables">
<refnamediv>
<refname>define_syslog_variables</refname>
<refpurpose>Initializes all syslog related constants</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>void</type><methodname>define_syslog_variables</methodname>
<void/>
</methodsynopsis>
<para>
Initializes all constants used in the syslog functions.
</para>
<para>
See also <function>openlog</function>,
<function>syslog</function> and
<function>closelog</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.fsockopen">
<refnamediv>
<refname>fsockopen</refname>
<refpurpose>
Open Internet or Unix domain socket connection
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>int</type><methodname>fsockopen</methodname>
<methodparam><type>string</type><parameter>hostname</parameter></methodparam>
<methodparam><type>int</type><parameter>port</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>errno</parameter></methodparam>
<methodparam choice="opt"><type>string</type><parameter>errstr</parameter></methodparam>
<methodparam choice="opt"><type>float</type><parameter>timeout</parameter></methodparam>
</methodsynopsis>
<para>
Initiates a stream connection in the Internet (AF_INET, using TCP
or UDP) or Unix (AF_UNIX) domain. For the Internet domain, it
will open a TCP socket connection to
<parameter>hostname</parameter> on port
<parameter>port</parameter>. <parameter>hostname</parameter> may
in this case be either a fully qualified domain name or an IP
address. For UDP connections, you need to explicitly specify the
protocol by prefixing <parameter>hostname</parameter> with
'<literal>udp://</literal>'. For the Unix domain,
<parameter>hostname</parameter> will be used as the path to the
socket, <parameter>port</parameter> must be set to 0 in this
case. The optional <parameter>timeout</parameter> can be used to
set a timeout in seconds for the connect system call.
</para>
<para>
<function>fsockopen</function> returns a file pointer which may
be used together with the other file functions (such as
<function>fgets</function>, <function>fgetss</function>,
<function>fputs</function>, <function>fclose</function>, and
<function>feof</function>).
</para>
<para>
If the call fails, it will return &false; and if the optional
<parameter>errno</parameter> and <parameter>errstr</parameter>
arguments are present they will be set to indicate the actual
system level error that occurred in the system-level
<literal>connect()</literal> call. If the value returned in
<parameter>errno</parameter> is <literal>0</literal> and the
function returned &false;, it is an indication that the error
occurred before the <literal>connect()</literal> call. This is
most likely due to a problem initializing the socket. Note that
the <parameter>errno</parameter> and
<parameter>errstr</parameter> arguments will always be passed by
reference.
</para>
<para>
Depending on the environment, the Unix domain or the optional
connect timeout may not be available.
</para>
<para>
The socket will by default be opened in blocking mode. You can
switch it to non-blocking mode by using
<function>socket_set_blocking</function>.
<example>
<title><function>fsockopen</function> Example</title>
<programlisting role="php">
<![CDATA[
<?php
$fp = fsockopen ("www.php.net", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br>\n";
} else {
fputs ($fp, "GET / HTTP/1.0\r\nHost: www.php.net\r\n\r\n");
while (!feof($fp)) {
echo fgets ($fp,128);
}
fclose ($fp);
}
?>
]]>
</programlisting>
</example>
The example below shows how to retrieve the day and time
from the UDP service "daytime" (port 13) in your own machine.
<example>
<title>Using UDP connection</title>
<programlisting role="php">
<![CDATA[
<?php
$fp = fsockopen("udp://127.0.0.1", 13, $errno, $errstr);
if (!$fp) {
echo "ERROR: $errno - $errstr<br>\n";
} else {
fwrite($fp,"\n");
echo fread($fp, 26);
fclose($fp);
}
?>
]]>
</programlisting>
</example>
<note>
<para>The timeout parameter was introduced in PHP 3.0.9 and
UDP support was added in PHP 4.
</para>
</note>
See also <function>pfsockopen</function>,
<function>socket_set_blocking</function>,
<function>socket_set_timeout</function>, <function>fgets</function>,
<function>fgetss</function>, <function>fputs</function>,
<function>fclose</function>, <function>feof</function>, and
the <link linkend="ref.curl">Curl extension</link>.
</para>
</refsect1>
</refentry>
<refentry id="function.gethostbyaddr">
<refnamediv>
<refname>gethostbyaddr</refname>
<refpurpose>
Get the Internet host name corresponding to a given IP address
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>string</type><methodname>gethostbyaddr</methodname>
<methodparam><type>string</type><parameter>ip_address</parameter></methodparam>
</methodsynopsis>
<para>
Returns the host name of the Internet host specified by
<parameter>ip_address</parameter>. If an error occurs, returns
<parameter>ip_address</parameter>.
</para>
<para>
See also <function>gethostbyname</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.gethostbyname">
<refnamediv>
<refname>gethostbyname</refname>
<refpurpose>
Get the IP address corresponding to a given Internet host name
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>string</type><methodname>gethostbyname</methodname>
<methodparam><type>string</type><parameter>hostname</parameter></methodparam>
</methodsynopsis>
<para>
Returns the IP address of the Internet host specified by
<parameter>hostname</parameter>.
</para>
<para>
See also <function>gethostbyaddr</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.gethostbynamel">
<refnamediv>
<refname>gethostbynamel</refname>
<refpurpose>
Get a list of IP addresses corresponding to a given Internet host
name
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>array</type><methodname>gethostbynamel</methodname>
<methodparam><type>string</type><parameter>hostname</parameter></methodparam>
</methodsynopsis>
<para>
Returns a list of IP addresses to which the Internet host
specified by <parameter>hostname</parameter> resolves.
</para>
<para>
See also <function>gethostbyname</function>,
<function>gethostbyaddr</function>,
<function>checkdnsrr</function>, <function>getmxrr</function>,
and the <literal>named(8)</literal> manual page.
</para>
</refsect1>
</refentry>
<refentry id="function.getmxrr">
<refnamediv>
<refname>getmxrr</refname>
<refpurpose>
Get MX records corresponding to a given Internet host name
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>int</type><methodname>getmxrr</methodname>
<methodparam><type>string</type><parameter>hostname</parameter></methodparam>
<methodparam><type>array</type><parameter>mxhosts</parameter></methodparam>
<methodparam choice="opt"><type>array</type><parameter>weight</parameter></methodparam>
</methodsynopsis>
<simpara>
Searches DNS for MX records corresponding to
<parameter>hostname</parameter>. Returns &true; if any records are
found; returns &false; if no records were found or if an error
occurred.
</simpara>
<simpara>
A list of the MX records found is placed into the array
<parameter>mxhosts</parameter>. If the
<parameter>weight</parameter> array is given, it will be filled
with the weight information gathered.
</simpara>
<simpara>
See also <function>checkdnsrr</function>,
<function>gethostbyname</function>,
<function>gethostbynamel</function>,
<function>gethostbyaddr</function>, and the
<literal>named(8)</literal> manual page.
</simpara>
</refsect1>
</refentry>
<refentry id="function.getprotobyname">
<refnamediv>
<refname>getprotobyname</refname>
<refpurpose>
Get protocol number associated with protocol name
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>int</type><methodname>getprotobyname</methodname>
<methodparam><type>string</type><parameter>name</parameter></methodparam>
</methodsynopsis>
<para>
<function>getprotobyname</function> returns the protocol number
associated with the protocol <parameter>name</parameter> as per
<filename>/etc/protocols</filename>.
</para>
<para>
See also: <function>getprotobynumber</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.getprotobynumber">
<refnamediv>
<refname>getprotobynumber</refname>
<refpurpose>
Get protocol name associated with protocol number
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>string</type><methodname>getprotobynumber</methodname>
<methodparam><type>int</type><parameter>number</parameter></methodparam>
</methodsynopsis>
<para>
<function>getprotobynumber</function> returns the protocol name
associated with protocol <parameter>number</parameter> as per
<filename>/etc/protocols</filename>.
</para>
<para>
See also: <function>getprotobyname</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.getservbyname">
<refnamediv>
<refname>getservbyname</refname>
<refpurpose>
Get port number associated with an Internet service and protocol
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>int</type><methodname>getservbyname</methodname>
<methodparam><type>string</type><parameter>service</parameter></methodparam>
<methodparam><type>string</type><parameter>protocol</parameter></methodparam>
</methodsynopsis>
<para>
<function>getservbyname</function> returns the Internet port
which corresponds to <parameter>service</parameter> for the
specified <parameter>protocol</parameter> as per
<filename>/etc/services</filename>.
<parameter>protocol</parameter> is either <literal>TCP</literal>
or <literal>UDP</literal>.
</para>
<para>
See also: <function>getservbyport</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.getservbyport">
<refnamediv>
<refname>getservbyport</refname>
<refpurpose>
Get Internet service which corresponds to port and protocol
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>string</type><methodname>getservbyport</methodname>
<methodparam><type>int</type><parameter>port</parameter></methodparam>
<methodparam><type>string</type><parameter>protocol</parameter></methodparam>
</methodsynopsis>
<para>
<function>getservbyport</function> returns the Internet service
associated with <parameter>port</parameter> for the specified
<parameter>protocol</parameter> as per <filename>/etc/services</filename>.
<parameter>protocol</parameter> is either <literal>TCP</literal>
or <literal>UDP</literal>.
</para>
<para>
See also: <function>getservbyname</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.ip2long">
<refnamediv>
<refname>ip2long</refname>
<refpurpose>
Converts a string containing an (IPv4) Internet Protocol dotted address
into a proper address.
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>int</type><methodname>ip2long</methodname>
<methodparam><type>string</type><parameter>ip_address</parameter></methodparam>
</methodsynopsis>
<para>
The function <function>ip2long</function> generates an IPv4 Internet
network address from its Internet standard format (dotted string)
representation.
<example>
<title><function>ip2long</function> Example</title>
<programlisting role="php">
<![CDATA[
<?php
$ip = gethostbyname("www.php.net");
$out = "The following URLs are equivalent:<br>\n";
$out .= "http://www.php.net/, http://".$ip."/, and http://".sprintf("%u",ip2long($ip))."/<br>\n";
echo $out;
?>
]]>
</programlisting>
</example>
<note>
<para>
Because PHP's integer type is signed, and many IP addresses will
result in negative integers, you need to use the "%u" formatter of
<function>sprintf</function> or <function>printf</function> to get
the string representation of the unsigned IP address.
</para>
</note>
This second example shows how to print a converted address with the
<function>printf</function> function :
<example>
<title>Displaying an IP address</title>
<programlisting role="php">
<![CDATA[
<?php
$ip = gethostbyname("www.php.net");
printf("%u\n", ip2long($ip));
echo $out;
?>
]]>
</programlisting>
</example>
</para>
<para>
See also: <function>long2ip</function>
</para>
</refsect1>
</refentry>
<refentry id="function.long2ip">
<refnamediv>
<refname>long2ip</refname>
<refpurpose>
Converts an (IPv4) Internet network address into a string in Internet
standard dotted format
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>string</type><methodname>long2ip</methodname>
<methodparam><type>int</type><parameter>proper_address</parameter></methodparam>
</methodsynopsis>
<para>
The function <function>long2ip</function> generates an Internet address
in dotted format (i.e.: aaa.bbb.ccc.ddd) from the proper address
representation.
</para>
<para>
See also: <function>ip2long</function>
</para>
</refsect1>
</refentry>
<refentry id="function.openlog">
<refnamediv>
<refname>openlog</refname>
<refpurpose>Open connection to system logger</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>int</type><methodname>openlog</methodname>
<methodparam><type>string</type><parameter>ident</parameter></methodparam>
<methodparam><type>int</type><parameter>option</parameter></methodparam>
<methodparam><type>int</type><parameter>facility</parameter></methodparam>
</methodsynopsis>
<para>
<function>openlog</function> opens a connection to the system
logger for a program. The string <parameter>ident</parameter> is
added to each message. Values for <parameter>option</parameter>
and <parameter>facility</parameter> are given below.
The <parameter>option</parameter> argument is used to indicate
what loggin options will be used when generating a log message.
The <parameter>facility</parameter> argument is used to specify what
type of program is logging the message. This allows you to specify
(in your machine's syslog configuration) how messages coming from
different facilities will be handled.
The use of <function>openlog</function> is optional. It
will automatically be called by <function>syslog</function> if
necessary, in which case <parameter>ident</parameter> will default
to &false;.
</para>
<para>
<table>
<title><function>openlog</function> Options</title>
<tgroup cols="2">
<thead>
<row>
<entry>Constant</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry>LOG_CONS</entry>
<entry>
if there is an error while sending data to the system logger,
write directly to the system console
</entry>
</row>
<row>
<entry>LOG_NDELAY</entry>
<entry>
open the connection to the logger immediately
</entry>
</row>
<row>
<entry>LOG_ODELAY</entry>
<entry>
(default) delay opening the connection until the first
message is logged
</entry>
</row>
<row>
<entry>LOG_PERROR</entry>
<entry>print log message also to standard error</entry>
</row>
<row>
<entry>LOG_PID</entry>
<entry>include PID with each message</entry>
</row>
</tbody>
</tgroup>
</table>
You can use one or more of this options. When using multiple options
you need to <literal>OR</literal> them, i.e. to open the connection
immediately, write to the console and include the PID in each message,
you will use: <literal>LOG_CONS | LOG_NDELAY | LOG_PID</literal>
</para>
<para>
<table>
<title><function>openlog</function> Facilities</title>
<tgroup cols="2">
<thead>
<row>
<entry>Constant</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry>LOG_AUTH</entry>
<entry>
security/authorization messages (use LOG_AUTHPRIV instead
in systems where that constant is defined)
</entry>
</row>
<row>
<entry>LOG_AUTHPRIV</entry>
<entry>security/authorization messages (private)</entry>
</row>
<row>
<entry>LOG_CRON</entry>
<entry>clock daemon (cron and at)</entry>
</row>
<row>
<entry>LOG_DAEMON</entry>
<entry>other system daemons</entry>
</row>
<row>
<entry>LOG_KERN</entry>
<entry>kernel messages</entry>
</row>
<row>
<entry>LOG_LOCAL0 ... LOG_LOCAL7</entry>
<entry>reserved for local use</entry>
</row>
<row>
<entry>LOG_LPR</entry>
<entry>line printer subsystem</entry>
</row>
<row>
<entry>LOG_MAIL</entry>
<entry>mail subsystem</entry>
</row>
<row>
<entry>LOG_NEWS</entry>
<entry>USENET news subsystem</entry>
</row>
<row>
<entry>LOG_SYSLOG</entry>
<entry>messages generated internally by syslogd</entry>
</row>
<row>
<entry>LOG_USER</entry>
<entry>generic user-level messages</entry>
</row>
<row>
<entry>LOG_UUCP</entry>
<entry>UUCP subsystem</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
<para>
See also <function>define_syslog_variables</function>,
<function>syslog</function> and
<function>closelog</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.pfsockopen">
<refnamediv>
<refname>pfsockopen</refname>
<refpurpose>
Open persistent Internet or Unix domain socket connection
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>int</type><methodname>pfsockopen</methodname>
<methodparam><type>string</type><parameter>hostname</parameter></methodparam>
<methodparam><type>int</type><parameter>port</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>errno</parameter></methodparam>
<methodparam choice="opt"><type>string</type><parameter>errstr</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>timeout</parameter></methodparam>
</methodsynopsis>
<para>
This function behaves exactly as <function>fsockopen</function>
with the difference that the connection is not closed after the
script finishes. It is the persistent version of
<function>fsockopen</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.socket-get-status">
<refnamediv>
<refname>socket_get_status</refname>
<refpurpose>
Returns information about existing socket resource
</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>array</type><methodname>socket_get_status</methodname>
<methodparam><type>resource</type><parameter>socket_get_status</parameter></methodparam>
</methodsynopsis>
<para>
Returns information about an existing socket resource. Currently
returns four entries in the result array:
</para>
<itemizedlist>
<listitem>
<para>
<parameter>timed_out</parameter> (bool) - The socket timed out
waiting for data
</para>
</listitem>
<listitem>
<para>
<parameter>blocked</parameter> (bool) - The socket was blocked
</para>
</listitem>
<listitem>
<para>
<parameter>eof</parameter> (bool) - Indicates EOF event
</para>
</listitem>
<listitem>
<para>
<parameter>unread_bytes</parameter> (int) - Number of bytes
left in the socket buffer
</para>
</listitem>
</itemizedlist>
<para>
See also: <function>socket_accept</function>,
<function>socket_bind</function>,
<function>socket_connect</function>,
<function>socket_listen</function>,
<function>socket_strerror</function>, and the
<link linkend="ref.sockets">Socket extension</link>.
</para>
</refsect1>
</refentry>
<refentry id="function.socket-set-blocking">
<refnamediv>
<refname>socket_set_blocking</refname>
<refpurpose>Set blocking/non-blocking mode on a socket</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>int</type><methodname>socket_set_blocking</methodname>
<methodparam><type>int</type><parameter>socket descriptor</parameter></methodparam>
<methodparam><type>int</type><parameter>mode</parameter></methodparam>
</methodsynopsis>
<para>
If <parameter>mode</parameter> is &false;, the given socket
descriptor will be switched to non-blocking mode, and if &true;, it
will be switched to blocking mode. This affects calls like
<function>fgets</function> that read from the socket. In
non-blocking mode an <function>fgets</function> call will always
return right away while in blocking mode it will wait for data to
become available on the socket.
</para>
<para>
This function was previously called as
<function>set_socket_blocking</function> but this usage is deprecated.
</para>
</refsect1>
</refentry>
<refentry id="function.socket-set-timeout">
<refnamediv>
<refname>socket_set_timeout</refname>
<refpurpose>Set timeout period on a socket</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>bool</type><methodname>socket_set_timeout</methodname>
<methodparam><type>int</type><parameter>socket descriptor</parameter></methodparam>
<methodparam><type>int</type><parameter>seconds</parameter></methodparam>
<methodparam><type>int</type><parameter>microseconds</parameter></methodparam>
</methodsynopsis>
<para>
Sets the timeout value on <parameter>socket descriptor</parameter>,
expressed in the sum of <parameter>seconds</parameter> and
<parameter>microseconds</parameter>.
<example>
<title><function>socket_set_timeout</function> Example</title>
<programlisting role="php">
<![CDATA[
<?php
$fp = fsockopen("www.php.net", 80);
if(!$fp) {
echo "Unable to open\n";
} else {
fputs($fp,"GET / HTTP/1.0\n\n");
$start = time();
socket_set_timeout($fp, 2);
$res = fread($fp, 2000);
var_dump(socket_get_status($fp));
fclose($fp);
print $res;
}
?>
]]>
</programlisting>
</example>
</para>
<para>
This function was previously called as
<function>set_socket_timeout</function> but this usage is deprecated.
</para>
<para>
See also: <function>fsockopen</function> and <function>fopen</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.syslog">
<refnamediv>
<refname>syslog</refname>
<refpurpose>Generate a system log message</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>int</type><methodname>syslog</methodname>
<methodparam><type>int</type><parameter>priority</parameter></methodparam>
<methodparam><type>string</type><parameter>message</parameter></methodparam>
</methodsynopsis>
<para>
<function>syslog</function> generates a log message that will be
distributed by the system logger.
<parameter>priority</parameter> is a combination of the facility
and the level, values for which are given in the next section.
The remaining argument is the message to send, except that the
two characters <literal>%m</literal> will be replaced by the
error message string (strerror) corresponding to the present
value of <errortype>errno</errortype>.
</para>
<para>
<table>
<title><function>syslog</function> Priorities (in descending order)</title>
<tgroup cols="2">
<thead>
<row>
<entry>Constant</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry>LOG_EMERG</entry>
<entry>system is unusable</entry>
</row>
<row>
<entry>LOG_ALERT</entry>
<entry>action must be taken immediately</entry>
</row>
<row>
<entry>LOG_CRIT</entry>
<entry>critical conditions</entry>
</row>
<row>
<entry>LOG_ERR</entry>
<entry>error conditions</entry>
</row>
<row>
<entry>LOG_WARNING</entry>
<entry>warning conditions</entry>
</row>
<row>
<entry>LOG_NOTICE</entry>
<entry>normal, but significant, condition</entry>
</row>
<row>
<entry>LOG_INFO</entry>
<entry>informational message</entry>
</row>
<row>
<entry>LOG_DEBUG</entry>
<entry>debug-level message</entry>
</row>
</tbody>
</tgroup>
</table>
</para>
<para>
<example>
<title>Using <function>syslog</function></title>
<programlisting role="php">
<![CDATA[
<?php
define_syslog_variables();
// open syslog, include the process ID and also send
// the log to standard error, and use a user defined
// logging mechanism
openlog("myScripLog", LOG_PID | LOG_PERROR, LOG_LOCAL0);
// some code
if (authorized_client()) {
// do something
} else {
// unauthorized client!
// log the attempt
$access = date("Y/m/d H:i:s");
syslog(LOG_WARNING,"Unauthorized client: $access $REMOTE_ADDR ($HTTP_USER_AGENT)");
}
closelog();
?>
]]>
</programlisting>
</example>
For information on setting up a user defined log handler, see the
<citerefentry><refentrytitle>syslog.conf</refentrytitle>
<manvolnum>5</manvolnum></citerefentry> Unix manual page. More
information on the syslog facilities and option can be found in the man
pages for <citerefentry><refentrytitle>syslog</refentrytitle>
<manvolnum>3</manvolnum></citerefentry> on Unix machines.
</para>
<para>
On Windows NT, the syslog service is emulated using the Event
Log.
</para>
<para>
See also <function>define_syslog_variables</function>,
<function>openlog</function> and
<function>closelog</function>.
</para>
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
|