fsockopen

PHP fsockopen to curl conversion

女生的网名这么多〃 提交于 2019-11-29 16:33:44
i have this piece of code: <?php $host = "registration.mypengo.com"; $request = "/webregistration.aspx?taskaction=serviceresponse&partner=157&subid=" . $subid . "&msisdn=" . $msisdn . "&type=TEXT&data=" . $data . "&serviceid=" . $service_id; $fp = fsockopen($host, 80, $errno, $errstr, 3.0); if($fp) { fwrite($fp, "GET $request HTTP/1.0\r\n" . "Host: $host\r\n". "Connection: close\r\n". "Content-Length: " . strlen($request) . "\r\n" . "\r\n" . $request); stream_set_timeout($fp, 2, 0); $response = ""; while(!feof($fp)) $response .= fread($fp, 1024); fclose($fp);?> i want to try it out using curl

PHP fsockopen to curl conversion

左心房为你撑大大i 提交于 2019-11-28 11:28:41
问题 i have this piece of code: <?php $host = "registration.mypengo.com"; $request = "/webregistration.aspx?taskaction=serviceresponse&partner=157&subid=" . $subid . "&msisdn=" . $msisdn . "&type=TEXT&data=" . $data . "&serviceid=" . $service_id; $fp = fsockopen($host, 80, $errno, $errstr, 3.0); if($fp) { fwrite($fp, "GET $request HTTP/1.0\r\n" . "Host: $host\r\n". "Connection: close\r\n". "Content-Length: " . strlen($request) . "\r\n" . "\r\n" . $request); stream_set_timeout($fp, 2, 0); $response

php 使用fsockopen 发送http请求

Deadly 提交于 2019-11-27 10:43:39
需求背景 在公司开发这么一个需求,每天三次定时催付待客服催付状态的订单,设定每天15、16、17点三次执行job任务来给一批订单打电话催付,需要三个时间点都把待客服催付的订单拨打一遍电话,根据数据组统计,大概每天需要催付的订单数量在6000左右,对接第三方电话呼叫业务,拿到订单信息来呼叫。 测试状态 拿500个订单手动执行第一波测试,发现500个订单催付完毕需要30多分钟,那么6000个订单按照需求催付时间点是完全不够的,半小时500个,一小时最多1000个。 初步排查,是由于使用php curl请求导致每一次遍历的请求时间慢,由于curl请求最短的time时间耗时是1秒,那么一小时3600秒也是不够呼完这6000单。 解决方案 一、在遍历循环的时候把每次请求的量丢入消费系统(队列),然后根据开启多个消费者来消费这些(上线迫在眉睫,来不及) 二、有没有类似curl更快的方案,发现了fsockopen,按照使用方法配置完500个订单,遍历完成只需要18秒。 需求代码 /** * 通过订单信息组装呼叫信息 * @param array $order * @return array */ private function getCallInfoByOrder ($order = []) { $order_ext = OrderExt::model()->getPrimary($order

Wordpress autologin using CURL or fsockopen in PHP

梦想的初衷 提交于 2019-11-27 06:22:34
问题 Client wants to click a link and auto login to Wordpress backend admin section. I tried using fsockopen, code below. Didn't work. $post_data['user_login'] = 'admin'; $post_data['user_pass'] = 'password'; $post_data['wp-submit'] = 'Log In'; $post_data['redirect_to'] = 'http://example.com/wp-admin/'; //traverse array and prepare data for posting (key1=value1) foreach ( $post_data as $key => $value) { $post_items[] = $key . '=' . $value; } //create the final string to be posted using implode()

php_network_getaddresses: getaddrinfo failed: Name or service not known

烈酒焚心 提交于 2019-11-27 03:48:30
Here is a snippet of my code $fp = fsockopen($s['url'], 80, $errno, $errstr, 5); if($fp){ fwrite($fp, $out); fclose($fp); When I run it, it outputs: unable to connect to www.mydomain.net/1/file.php:80 (php_network_getaddresses: getaddrinfo failed: Name or service not known I'm using this to submit GET data to the $s['url'] I can't figure out why. Any help would be greatly appreciated. If you only want to submit GET data to the URL, you should use something straightforward like file_get_contents(); $myGetData = "?var1=val1&var2=val2"; file_get_contents($url.$myGetData); You cannot open a

How to check if a file exists from a url

不想你离开。 提交于 2019-11-26 20:05:54
I need to check if a particular file exists on a remote server. Using is_file() and file_exists() doesn't work. Any ideas how to do this quickly and easily? Amila You have to use CURL function does_url_exists($url) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_NOBODY, true); curl_exec($ch); $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($code == 200) { $status = true; } else { $status = false; } curl_close($ch); return $status; } You don't need CURL for that... Too much overhead for just wanting to check if a file exists or not... Use PHP's get_header . $headers=get_headers($url); Then

Socket transport “ssl” in PHP not enabled

佐手、 提交于 2019-11-26 18:38:45
I'm having trouble enabling the socket transport "ssl" in PHP. When I run my script, I get the error: Warning: fsockopen() [function.fsockopen]: unable to connect to ssl://www.my.site.com:443 (Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?) I'm running IIS6 on Windows and this is what I've done so far to try to get it working: uncommented the php_openssl.dll and php_sockets.dll extensions in php.ini made sure PHP was loading the ini file I made changes to (it is, and it's definitely loading other extensions, so I'm fairly sure this isn't the

PHP Post data with Fsockopen

 ̄綄美尐妖づ 提交于 2019-11-26 14:16:52
问题 I am attempting to post data using fsockopen, and then returning the result. Here is my current code: <?php $data="stuff=hoorah\r\n"; $data=urlencode($data); $fp = fsockopen("www.website.com", 80, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)<br />\n"; } else { $out = "POST /script.php HTTP/1.0\r\n"; $out .= "Host: www.webste.com\r\n"; $out .= 'Content-Type: application/x-www-form-urlencoded\r\n'; $out .= 'Content-Length: ' . strlen($data) . '\r\n\r\n'; $out .= "Connection: Close\r