What are some common protocols used for transferring data in PHP applications?
When transferring data in PHP applications, some common protocols used include HTTP, FTP, SMTP, and SOAP. These protocols help facilitate the communication and exchange of data between different systems or servers.
// Example of transferring data using HTTP protocol
$url = 'http://example.com/api';
$data = ['key1' => 'value1', 'key2' => 'value2'];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
$response = curl_exec($ch);
curl_close($ch);
echo $response;