<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.swoole-event.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'fr',
  ),
  'this' => 
  array (
    0 => 'swoole-event.write.php',
    1 => 'Swoole\\Event::write',
    2 => '&Eacute;crit des donn&eacute;es sur un socket de mani&egrave;re asynchrone',
  ),
  'up' => 
  array (
    0 => 'class.swoole-event.php',
    1 => 'Swoole\\Event',
  ),
  'prev' => 
  array (
    0 => 'swoole-event.wait.php',
    1 => 'Swoole\\Event::wait',
  ),
  'next' => 
  array (
    0 => 'class.swoole-exception.php',
    1 => 'Swoole\\Exception',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'fr',
    'path' => 'reference/swoole/swoole/event/write.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="swoole-event.write" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Swoole\Event::write</h1>
  <p class="verinfo">(PECL swoole &gt;= 1.9.0)</p><p class="refpurpose"><span class="refname">Swoole\Event::write</span> &mdash; <span class="dc-title">Écrit des données sur un socket de manière asynchrone</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-swoole-event.write-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="modifier">static</span> <span class="modifier">function</span> <span class="methodname"><strong>Swoole\Event::write</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span> <code class="parameter">$fd</code></span>, <span class="methodparam"><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span> <code class="parameter">$data</code></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="simpara">
   Rend l&#039;envoi de données asynchrone pour les ressources de flux et de sockets.
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="simpara">
    Si des données sont écrites en continu sur un socket alors que le pair ne les
    lit pas assez vite, le tampon du socket finit par être saturé. Dans ce cas, la
    couche basse de Swoole stocke les données excédentaires dans un tampon en
    mémoire et attend le déclenchement de l&#039;événement d&#039;écriture avant de tenter
    d&#039;écrire à nouveau sur le socket. Cependant, si ce tampon en mémoire est lui
    aussi saturé, Swoole émet l&#039;erreur « pipe buffer overflow, reactor will block »
    et bascule en mode bloquant, suspendant les écritures suivantes jusqu&#039;à ce que
    de la place se libère.
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="simpara">
    Le retour de <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> lorsque le tampon est saturé est une opération atomique :
    soit la totalité des données est écrite, soit rien ne l&#039;est.
   </p>
  </p></blockquote>
  <div class="warning"><strong class="warning">Avertissement</strong>
   <p class="simpara">
    Event::write ne peut pas être utilisée avec des flux ou des sockets chiffrés
    en SSL/TLS (connexions tunnelisées).
   </p>
  </div>
  <div class="warning"><strong class="warning">Avertissement</strong>
   <p class="simpara">
    En cas de succès, Event::write bascule automatiquement $socket en mode non
    bloquant.
   </p>
  </div>
 </div>


 <div class="refsect1 parameters" id="refsect1-swoole-event.write-parameters">
  <h3 class="title">Liste de paramètres</h3>
  <dl>
   
    <dt><code class="parameter">fd</code></dt>
    <dd>
     <p class="simpara">
      Descripteur de fichier (ressource de flux ou de socket, entier, ou objet).
     </p>
    </dd>
   
   
    <dt><code class="parameter">data</code></dt>
    <dd>
     <p class="simpara">
      Données à envoyer (leur longueur ne doit pas dépasser la taille du tampon du
      socket).
     </p>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-swoole-event.write-returnvalues">
  <h3 class="title">Valeurs de retour</h3>
  <p class="simpara">
   Cette fonction retourne <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> en cas de succès ou <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> si une erreur survient.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-swoole-event.write-examples">
  <h3 class="title">Exemples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Exemple #1 Exemple avec <span class="function"><strong>Swoole\Event::write()</strong></span></strong></p>
    <div class="example-contents">
     <div class="phpcode"><pre><code style="color: #000000"><span style="color: #0000BB">&lt;?php
</span><span style="color: #007700">use </span><span style="color: #0000BB">Swoole\Event</span><span style="color: #007700">;

</span><span style="color: #0000BB">$fp </span><span style="color: #007700">= </span><span style="color: #0000BB">stream_socket_client</span><span style="color: #007700">(</span><span style="color: #DD0000">'tcp://127.0.0.1:9501'</span><span style="color: #007700">);
</span><span style="color: #0000BB">$data </span><span style="color: #007700">= </span><span style="color: #0000BB">str_repeat</span><span style="color: #007700">(</span><span style="color: #DD0000">'A'</span><span style="color: #007700">, </span><span style="color: #0000BB">1024 </span><span style="color: #007700">* </span><span style="color: #0000BB">1024</span><span style="color: #007700">*</span><span style="color: #0000BB">2</span><span style="color: #007700">);
</span><span style="color: #0000BB">Event</span><span style="color: #007700">::</span><span style="color: #0000BB">add</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">, function(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">) {
     echo </span><span style="color: #0000BB">fread</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);
});
</span><span style="color: #0000BB">Event</span><span style="color: #007700">::</span><span style="color: #0000BB">write</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">, </span><span style="color: #0000BB">$data</span><span style="color: #007700">);
</span><span style="color: #0000BB">?&gt;</span></code></pre></div>
    </div>

   </div>
  </p>
 </div>

</div><?php manual_footer($setup); ?>