You could try this. i think this option CURLOPT_LOCALPORT is what you're looking for
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://example.com/");
curl_setopt($ch, CURLOPT_PORT, [destinationport]);
curl_setopt($ch, CURLOPT_LOCALPORT, [sourceport]);
$output = curl_exec($ch);
curl_close($ch);
print($output);