php curl get和post使用方法

https://www.jianshu.com/p/b72572a11e37

封装的方法:https://www.cnblogs.com/CHEUNGKAMING/p/5717429.html

请求头,响应头
https://www.cnblogs.com/tianye8123/p/5942643.html
伪造ip
https://www.cnblogs.com/qunshu/p/3367482.html

curl 当时访问
https://www.cnblogs.com/mingforyou/p/3930636.html

https://blog.csdn.net/richangbiji/article/details/81667725

定时任务启动
https://blog.csdn.net/LOUISLIAOXH/article/details/48242289
周一到周五
https://www.cnblogs.com/mingforyou/p/3930636.html

实现秒级别定时
https://www.cnblogs.com/handle/p/9246197.html

注意修改文件权限777

55  9  *  *  1-5  mail -s "hi" alex@domain.name   /dev/null 2>&1
//九点55分周一到周五
55 9 * * 1-5 /bin/sh /home/guofu.sh
55 20 * * 1-5 /bin/sh /home/guofu.sh


/usr/bin/curl http://www.baidu.com  >> /home/guofu.txt

/etc/init.d/cron reload
 /etc/init.d/cron stop 

http://my_tp.com/
# m h  dom mon dow   command
# */1 * * * * date >> /home/testCron.txt
# */1 * * * * /usr/bin/curl http://www.baidu.com  >> /home/guofu.txt
# */1 * * * * /bin/sh /home/guofu.sh
55 9 * * * /bin/sh /home/guofu.sh
55 20 * * * /bin/sh /home/guofu.sh

秒级别定时
sleep 5;/usr/bin/curl http://my_tp.com  >> /home/guofu.txt
date >> /home/guofu.txt

封装的方法
function curl_get($url, $timeout = 5)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    curl_setopt ( $ch,  CURLOPT_NOSIGNAL,true);
    $file_contents = curl_exec($ch);
    curl_close($ch);
    return $file_contents;
}

function curl_post($url, array $params = array(), $timeout)
{
    $ch = curl_init();//初始化
    curl_setopt($ch, CURLOPT_URL, $url);//抓取指定网页
    curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
    curl_setopt ( $ch,  CURLOPT_NOSIGNAL,true);//忽略所有的curl传递给php进行的信号 避免curl timeout was reached(毫秒超时bug)
    curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
    $data = curl_exec($ch);//运行curl
    curl_close($ch);
    return ($data);
}


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容