I've developed a simple streams class to handle get, post and put requests (based on the documentation and user notes here).
The simplest example:
<?php
// a simple GET request:
include('eac_streams.class.php');
$http = new stream();
$result = ('http://www.domain.com/somepage.php');
?>
Along with that, I have a curl class that does nearly the same thing.
http://www.kevinburkholder.com/sw_curl_stream.php
Hope it's useful. Any feedback is welcomed.
Thanks.
[note: cross-posted to curl page]
Fonctions sur les flux
Sommaire
- stream_bucket_append — Ajoute un compartiment au corps
- stream_bucket_make_writeable — Retourne un objet de compartiment depuis le corps pour des opérations sur celui-ci
- stream_bucket_new — Crée un nouveau compartiment pour l'utiliser sur le flux courant
- stream_bucket_prepend — Ajout initial d'un compartiment au corps
- stream_context_create — Crée un contexte de flux
- stream_context_get_default — Lit le contexte par défaut des flux
- stream_context_get_options — Lit la valeur des options pour un flux/gestionnaire/contexte
- stream_context_set_default — Set the default streams context
- stream_context_set_option — Configure une option pour un flux/gestionnaire/contexte
- stream_context_set_params — Configure les paramètres pour un flux/gestionnaire/contexte
- stream_copy_to_stream — Copie des données depuis un flux vers un autre
- stream_encoding — Définit le jeu de caractères pour l'encodage du flux
- stream_filter_append — Attache un filtre à un flux en fin de liste
- stream_filter_prepend — Attache un filtre à un flux en début de liste
- stream_filter_register — Enregistre un filtre de flux
- stream_filter_remove — Supprime un filtre d'un flux
- stream_get_contents — Lit le reste d'un flux dans une chaîne
- stream_get_filters — Liste les filtres enregistrés
- stream_get_line — Lit une ligne dans un flux
- stream_get_meta_data — Lit les en-têtes et données méta des flux
- stream_get_transports — Liste les gestionnaires de transports de sockets disponibles
- stream_get_wrappers — Liste les gestionnaires de flux
- stream_notification_callback — Une fonction de rappel pour le paramètre de contexte notification
- stream_register_wrapper — Alias de stream_wrapper_register
- stream_resolve_include_path — Détermine quel fichier sera ouvert lors des appels à la fonction fopen avec un chemin relatif
- stream_select — Retourne l'équivalent de l'appel système select() sur un tableau de flux avec un délai d'expiration spécifié par tv_sec et tv_usec
- stream_set_blocking — Configure le mode bloquant d'un flux
- stream_set_timeout — Configure la durée d'expiration d'un flux
- stream_set_write_buffer — Configure la bufferisation de fichier pour un flux
- stream_socket_accept — Accepte une connexion sur une socket créée par stream_socket_server
- stream_socket_client — Ouvre une connexion socket Internet ou Unix
- stream_socket_enable_crypto — Active ou non le chiffrement, pour une socket déjà connectée
- stream_socket_get_name — Lit le nom des sockets locale ou distante
- stream_socket_pair — Crée une paire de sockets connectées et indissociables
- stream_socket_recvfrom — Lit des données depuis une socket, connectée ou pas
- stream_socket_sendto — Envoie une message à la socket, connectée ou pas
- stream_socket_server — Crée une socket serveur Unix ou Internet
- stream_socket_shutdown — Arrête une connexion full-duplex
- stream_wrapper_register — Enregistre une enveloppe URL, implémentée comme une classe PHP
- stream_wrapper_restore — Restaure un gestionnaire d'URL supprimé
- stream_wrapper_unregister — Supprime un gestionnaire d'URL
Fonctions sur les flux
kburkholder at earthasylum dot com
10-Mar-2008 03:43
10-Mar-2008 03:43
marcus at synchromedia dot co dot uk
15-Nov-2007 03:13
15-Nov-2007 03:13
I can't find any real documentation on the quoted-printable-encode stream filter, but I've gathered info from several places. It seems there are 4 options that can be passed in the param array as in my other note on this subject:
line-length: integer, simply sets line length before a soft break is inserted
line-break-chars: Which char or chars to consider as a line break - note that "\r\n" will only match CRLF, not CR or LF, so make sure it matches your content.
binary: boolean, hex encodes all control chars, including spaces and line breaks, but leaves alphanumerics untouched
force-encode-first: Forcibly hex-encodes the first char on each line, even if it's alphanumeric. This is useful for avoiding corruption in some incompetent mail servers, like Exchange.
marcus at synchromedia dot co dot uk
30-Oct-2006 10:16
30-Oct-2006 10:16
As this article says, there is no quoted_printable_encode function() in PHP: http://www.zend.com/manual/filters.convert.php
However there is a stream filter for quoted printable encoding. Here's an example function that produces output suitable for email and doesn't explicitly use external files (though it might do for strings over 2Mb due to the nature of the temp stream type):
<?php
function quoted_printable_encode($string) {
$fp = fopen('php://temp/', 'r+');
$params = array('line-length' => 70, 'line-break-chars' => "\r\n");
stream_filter_append($fp, 'convert.quoted-printable-encode', STREAM_FILTER_READ, $params);
fputs($fp, $string);
rewind($fp);
return stream_get_contents($fp);
}
echo quoted_printable_encode(str_repeat("hello there ", 50)." a=1\r\n")."\n";
?>
The filter needs to be restricted to STREAM_FILTER_READ because by default it will get filtered both going into and out of the stream, and will thus get encoded twice.
It should be much faster than using a PHP implementation of the same thing, though note that this will only work in PHP 5.1+.
jausions at php dot net
15-May-2006 08:59
15-May-2006 08:59
For the "notification" index of the $params for stream_context_set_params() function, a callable function is accepted. That is array(&$object, 'methodName') will also work.
