To write to a stream, you use the fwrite() function. This function takes two arguments: the stream to write to, and the data to write. For example, fwrite($stream, 'Hello, World!') would write the string 'Hello, World!' to the stream.