首页 > 编程语言 >php 异步形式调取导出数据

php 异步形式调取导出数据

时间:2023-05-12 16:48:21浏览次数:30  
标签:异步 header file path curl php data 调取

php部分

ajax请求此部分
function aysncexec()
    {

        $lock_file = 'filelock.lock';

        if (file_exists($lock_file)) {
            exit(json_encode(array('code' => 0)));
        }

        $url = base_url() . 'execcmd';


        $this->_curl($url, [], 1);

        exit(json_encode(array('code' => 1)));
    }


_curl($url, $data = null, $timeout = 1)
    {


        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
        if ($timeout > 0) { //超时时间秒
            curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
        }
        $output = curl_exec($curl);
        $error = curl_errno($curl);
        curl_close($curl);
        if ($error) {
            return false;
        }
        return $output;
    }


curl执行此部分
function execcmd($keys = "")
    {




        $datas = $this->input->post(null, true);




        if (!empty($datas)) {
            $search_file = 'search.json';

            unlink($search_file);

            file_put_contents('search.json', json_encode($datas, JSON_UNESCAPED_UNICODE));
        }


        $php_path = '/opt/modules/php/bin/php';
        ignore_user_abort(true); // 忽略客户端断开 
        set_time_limit(0);       // 设置执行不超时
        $index_path = APPPATH . 'index.php';
        $clis = $php_path . " " . $index_path . '2>&1';
        exec($clis, $output);


    }

下载

function downloads()
    {
        $file_path ='data/e.xlsx';
        $lock_file =  'data/filelock.lock';
        $search_file ='data/search.json';

        $filesize = filesize($file_path);

        header('Content-Description:File Transfer');
        header('Content-Type:application/octet-stream');
        header('Content-Transfer-Encoding:binary');
        header('Accept-Ranges: bytes');
        header('Expires:0');
        header('Cache-Control:must-revalidate');
        header('Pragma:public');
        header('Content-Length:' . $filesize);
        header('Content-Disposition:attachment;filename=tests.xlsx');
        $fp = fopen($file_path, 'rb');
        fseek($fp, 0);
        while (!feof($fp)) {
            echo fread($fp, 1024 * 8); //输出文件
            flush(); //输出缓冲
            ob_flush();
        }
        fclose($fp);
        unlink($file_path);
        unlink($lock_file);
        unlink($search_file);
        exit();
    }

html部分

   $.ajax({
                  method: "POST",
                  url: "aysncexec",
                  data: data_search,
                  dataType: "json",
                  timeout: 5000 
                }).success(function(res){
                  layer.close(index);
                  if (res.code=="0") {
                    alert("正在运行");
                    return;
                  } else {
                    
                    window.location.reload();
                  }
                  
                }).done(function(data) {
                
                    console.log(data.fridge);
                }).fail(function(jqXHR, status) {
                    
                    console.log(status);
                    
                });

遇见的问题:nginx 499 错误
php 主动断开 查看php目录 权限不对

标签:异步,header,file,path,curl,php,data,调取
From: https://www.cnblogs.com/mengluo/p/17395004.html

相关文章

  • php获取目录下所有文件及目录
    来源:http://www.shanhubei.com/archives/2614.htmlhttp://www.shanhubei.com/archives/1940.html获取某目录下所有子文件和子目录functiongetDirContent($path){if(!is_dir($path)){returnfalse;}//readdir方法/*$dir=opendir($path);......
  • 异步机无感算法解析 提供推导文档,模型,代码…… md500
    异步机无感算法解析提供推导文档,模型,代码……md500ID:442500634075285690......
  • mysql:安装phpmyadmin(phpMyAdmin 5.2.1 / PHP 8.2.5 / mysqld 8.0.33)
    一,下载phpmyadmin:官网:https://www.phpmyadmin.net/如图: 注意不同版本的环境需求可以得到下载地址后直接在linux上wget[root@imgphpmyadmin]#wgethttps://files.phpmyadmin.net/phpMyAdmin/5.2.1/phpMyAdmin-5.2.1-all-languages.zip解压:[root@imgphpmyadm......
  • Thinkphp5.1允许uni-app的H5跨域请求接口解决方法
    情景:   uni-app使用vue框架开发混合APP,虽然APP或者小程序没有跨域,但希望就是写完这个既有H5,又有APP,小程序等,所以能通过后端解决跨域最好。但是不知道是vue的原因还是什么,在PHP接口基类中添加了header头完全不起作用。官方给出的方法也有,具体可以看https://uniapp.dcloud.io/ap......
  • python异步正则字符串替换,asyncio异步正则字符串替换re
     自然语言处理经常使用re正则模块进行字符串替换,但是文本数量特别大的时候,需要跑很久,这就需要使用asyncio异步加速处理importpandasaspdimportreimportasynciodata=pd.read_csv("guba_all_post_20230413.csv")data.dropna(inplace=True)#defreplace_betwee......
  • python异步字符串查找,asyncio和marisa_trie
     自然语言处理当中经常需要字符串的查找操作,比如通过查找返回字串在文本当中的位置,比如通过匹配实现的nerimportpandasaspdimportasyncio#data=pd.read_csv("guba_fc_result_20230413.csv")data=pd.read_csv("guba_all_post_20230413.csv")filename="cate_gr......
  • 在PhpStorm项目工具窗口中显示.idea文件夹
    转自:https://www.codenong.com/33010238/ 对于.idea,它也有专用的注册表设置(默认情况下,我至少在PhpStorm中启用了此设置)Help|FindAction...并查找registry(或在Windows上使用默认键盘映射通过Maintenance Ctrl+Alt+Shift+/)进入内部-查找projectView.hide.dot.idea条......
  • php:配置php.ini(PHP 8.2.5)
    一,配置错误日志1,注意在生产环境中保持以下各项的默认值:error_reporting=E_ALL&~E_DEPRECATED&~E_STRICTdisplay_errors=Offlog_errors=On说明:如果display_error=On则会在页面上显示报错信息,这在生产环境中是不允许的,如图:所以不要修改生产环境中的disp......
  • php:配置php-fpm(PHP 8.2.5)
    一,创建php日志的存放目录:[root@imgetc]#mkdir/web/logs/phplogs[root@imgetc]#chmod777/web/logs/phplogs/二,配置php-fpm编辑配置文件的命令:root@img~]#cd/usr/local/soft/php8.2.5/etc/[root@imgetc]#cdphp-fpm.d/[[email protected]]#viwww.conf1......
  • 异步电机的VVVF的C代码+仿真模型,C代码可直接在simulink模型里进行在线仿真,所见即所得,
    异步电机的VVVF的C代码+仿真模型,C代码可直接在simulink模型里进行在线仿真,所见即所得,仿真模型为离散化模型,C代码嵌入到模型里进行在线仿真,仿真通过后可以直接移植到各种MCU芯片里:1.直接带满载启动,转速超调小,控制精度高2.四种不同的VF曲线可供选择:直线VF,分段VF,抛物线VF,S......