title: Encrypt file with PHP OpenSSL
body: <p>Usually, I use <code>openssl_encrypt</code> to encrypt simple string with AES in PHP, and it works pretty well.</p>
  
  <p>Now I need to encrypt files with AES-256-CTR mode, but the only way to do this is to <code>file_get_contents</code> the entire content of the file and then send it to the <code>openssl_encrypt</code> function to encrypt the actual file data. The problem is this method is very "poor" because of the critical waste of memory. </p>
  
  <p>1) Is there a way to work with chunked data with PHP OpenSSL ?</p>
  
  <p>For example:</p>
  
  <pre><code>&lt;?php
  // ...
  $f = fopen('large.iso','r');
    while(feof($f)){
      $chunk = fread($f,16);
         $cipher = openssl_encrypt(...$chunk...);
      // ... code ...
     }
      // ... more code ...
  ?&gt;
  </code></pre>
  
  <p>2) <code>openssl_encrypt</code> official documentation is not published yet. Does someone could clarify the meaning of the parameters of the function for use with AES-CTR mode? Does the counter is handled automatically? Is it necessary to apply a manual XOR the data returned by the function?</p>
  
  <p>Note: It is a professional project so I don't want to use <code>phpseclib</code> or others' "anonymous" libraries, nor do I don't want to use the command line as well.</p>