【问题标题】:How exec() works - PHP and Wordpressexec() 如何工作 - PHP 和 Wordpress
【发布时间】:2019-02-22 18:40:03
【问题描述】:

我正在使用wordpress,并且我在csv 中有一个文章列表,我在php 中的函数已经在theme_options.php 文件中以及wordpress 主题的其他各种功能中工作,但我会喜欢只在后台运行注册 csv this 的函数。

我想了解如何在后台运行我的函数

我知道这是一个非常笼统的问题,但我想了解 exec 的工作原理以及我应该在什么时候在我的函数中调用它

function example() {

    if( isset( $_POST['submit'] ) ) {       

        $lines = file(''.get_template_directory_uri() . '/list.csv', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES | FILE_TEXT);

        foreach ($lines as $line_num => $line){ 

                //some code to save csv line content            
        }
    }
} 
add_action( 'init', 'example' );

编辑

这样对吗?

csv_test.php代码:

            $lines = file(''.get_template_directory_uri() . '/list.csv', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES | FILE_TEXT);

            foreach ($lines as $line_num => $line){ 

                    //some code to save csv line content            
            }

theme_options.php代码:

     function example() { 
 if( isset( $_POST['submit'] ) ) {              
            exec("php csv_test.php > /dev/null &");
        } 
}
        add_action( 'init', 'example' );

【问题讨论】:

  • 你想做什么?在高清中保存文件?
  • @Vidal 我编辑了我的问题,请参阅

标签: php shell exec


【解决方案1】:

使用 exec,您可以执行外部程序。 http://php.net/manual/en/function.exec.php

要在后台运行,您可以创建一个 cron 作业并运行 wget url。

【讨论】:

    猜你喜欢
    • 2010-11-09
    • 2011-12-14
    • 1970-01-01
    • 2019-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多