returns TCP addresses for TCP and UDP addresses for UDP requests respectively.
Also, when a connect call "returns" EINPROGRESS and the full timeout limit
has not yet been reached, retry the select with the remaining time interval.
This is a potential fix for Bug #21653.
# Note: atm, the fix is Linux specific; will do some more work to make this
# portable at the weekend.
https:// streams.
This code is essential for people writing secure applications in order to avoid
man-in-the-middle attacks, and is thus regarded as a bug fix.
It is, however, optional; you need to explicitly turn on the verification
functionality, as it depends on you to specify your trusted certificate chain.
This sample demonstrates a secured https:// request, making use of the CA
bundle provided by curl:
<?php
$ctx = stream_context_create();
// Turn on verification
stream_context_set_option($ctx, "ssl", "verify_peer", true);
// Set the CA bundle (trusted certificate chain)
stream_context_set_option($ctx, "ssl", "cafile",
"/usr/local/share/curl/curl-ca-bundle.crt");
$fp = fopen("https://www.zend.com", "rb", false, $ctx);
?>
This sample demonstrates how to roll your own https:// request, and specify a
certificate to use for authentication; the local_cert and passphrase options
will also work for fopen().
<?php
$ctx = stream_context_create();
stream_context_set_option($ctx, "ssl", "verify_peer", true);
stream_context_set_option($ctx, "ssl", "cafile",
"/usr/local/share/curl/curl-ca-bundle.crt");
// set local cert. it MUST be a PEM encoded file containing the certificate
// AND your private key. It can also contain the certificate chain of issuers.
stream_context_set_option($ctx, "ssl", "local_cert", "/path/to/my/cert.pem");
stream_context_set_option($ctx, "ssl", "passphrase", "secret!");
// Set the common name that we are expecting; PHP will perform limited wildcard
// matching. If the CN does not match this, the connection attempt will fail.
// The value to specify will always be the same as the Host: header you specify.
stream_context_set_option($ctx, "ssl", "CN_match", "secure.sample.domain");
$ssl = fsockopen("ssl://secure.sample.domain", 443, $errno, $errstr, 10, $ctx);
if ($ssl) {
fwrite($ssl, "GET / HTTP/1.0\r\nHost: secure.sample.domain\r\n\r\n");
fpassthru($ssl);
}
?>
A Simple fix for Bug #12360 (fsockopen timeout doesn't work).
Analysis:
On systems with HAVE_GETADDRINFO and IPV6 support, php_hostconnect would
attempt to connect to each possible address that matched the requested IP.
If the remote host:port combination are dropping packets this would cause the
first connection to timeout (after waiting for the full timeout duration).
PHP would then attempt the second address and wait the full duration again.
Solution:
If the first connection attempt times out, abort the connection loop.
I've moved EOF detection into the streams layer; a stream reader
implementation should set stream->eof when it detects EOF.
Fixed test for user streams - it still fails but that is due to an output
buffering bug.
with regard to sockets. The behaviour should be aligned with PHP 4.2 now.
This has been verified to some degree.
If the underlying stream operations block when no new data is readable,
we need to take extra precautions.
If there is buffered data available, we check for a EOL. If it exists,
we pass the data immediately back to the caller. This saves a call
to the read implementation and will not block where blocking
is not necessary at all.
If the stream buffer contains more data than the caller requested,
we can also avoid that costly step and simply return that data.
Eliminate similar code from network.c.
Implement fgets equivalent at the streams level, which can detect
the mac, dos and unix line endings and handle them appropriately.
The default behaviour is unix (and dos) line endings.
An ini option to control this behaviour will follow.
# Don't forget to make clean!
# I've done some testing but would appreciate feedback from
# people with scripts/extensions that seek around a lot.
php_stream_set_option which can be used in a similar way as ioctl()
to set options for streams.
Current options include buffering and blocking support.
o Buffer control is support for stdio based streams.
o Blocking/non-blocking is supported for stdio and socket based streams.