php - 使用代理的php套接字连接
问题描述
我有一个具有套接字连接的 PHP 应用程序。我正在考虑在其中集成代理,以便我可以使用代理进行连接。我当前的连接代码如下
public function connect()
{
if ($this->isConnected()) {
return true;
}
/* Create a TCP/IP socket. */
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket !== false) {
$result = socket_connect($socket, 'e'.rand(1, 16).'.myserver.net', Constants::PORT);
if ($result === false) {
$socket = false;
}
}
if ($socket !== false) {
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, ['sec' => Constants::TIMEOUT_SEC, 'usec' => Constants::TIMEOUT_USEC]);
socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO, ['sec' => Constants::TIMEOUT_SEC, 'usec' => Constants::TIMEOUT_USEC]);
$this->socket = $socket;
$this->eventManager()->fire('onConnect',
[
$this->phoneNumber,
$this->socket,
]
);
$this->logFile('info', 'Connected to server');
return true;
} else {
$this->logFile('error', 'Failed to connect server');
$this->eventManager()->fire('onConnectError',
[
$this->phoneNumber,
$this->socket,
]
);
return false;
}
}
让我知道是否有人有可靠的想法。谢谢
解决方案
推荐阅读
- sqlite - 如何为约束名称编写 Fluent NHibernate 约定?
- r - 如何使用创建的机器学习模型创建仪表板
- c# - ASP.NET CORE 3.1:Azure AD 身份验证在 EDGE 中失败。身份验证期间无限重定向循环和页面重新加载
- python - 如何使用 matplotlib 降低时间序列的索引刻度频率
- npm - 将 Sveltekit 应用程序部署到 Netlify 时,构建中断并出现错误“@supabase/supabase-js”不提供名为“createClient”的导出。怎么修?
- python - 循环中的变量更新错误 - Python(Q-learning)
- google-cloud-firestore - Firestore 云功能 - 每次将文档添加到不同的集合(不是“用户”)时,我可以向用户发送电子邮件吗?
- apache-flink - 当会话窗口因不活动而到期时如何触发函数
- field - 全球化(阿拉伯语)
- python - 如何消除使用 pandas 和 matplotlib 运行脚本时出现的对角线?