AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 784918
Accepted
uberrebu
uberrebu
Asked: 2016-06-20 12:14:05 +0800 CST2016-06-20 12:14:05 +0800 CST 2016-06-20 12:14:05 +0800 CST

PHP解析错误语法错误,文件意外结束

  • 772

当我在 LEMP 设置 nginx 1.10/PHP 7 时,我一直收到此错误,我认为这是因为 PHP 7,现在我使用 nginx 1.4.6/PHP 5.5.9 设置了一个新服务器

2016/06/19 15:45:18 [error] 4094#0: *1 FastCGI sent in stderr: "PHP message: PHP Parse error:  syntax error, unexpected end of file in /var/www/www.example.com/public/wp-content/themes/techs/functions.php on line 141" while reading response header from upstream, client: 10.0.0.11, server: www.example.com, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "example.com"

现在导致此错误的文件在这里,我注意到该行是空的最后一行,我试图删除该行但不会被删除。谁能指出导致此错误的原因?

纳米/var/www/www.example.com/public/wp-content/themes/techs/functions.php

第 141 行是结束标签之后/下方的空行;每次删除该行的尝试都失败了

<?php

if ( function_exists( 'add_theme_support' ) ) { // Added in 2.9
        add_theme_support( 'post-thumbnails' );
        set_post_thumbnail_size( 75, 56, true ); // Normal post thumbnails
        add_image_size( 'single-post-thumbnail', 273, 273 ); // Permalink thumbnail size
}


/*register_sidebar(array(
        'name'=>'sidebar',
    'before_widget' => '<li id="%1$s" class="widget %2$s">',
    'after_widget' => '</li>',
    'before_title' => '<h2 class="widgettitle">',
    'after_title' => '</h2>',
));
*/

# Displays a list of popular posts
function gtt_popular_posts($num, $pre='<li>', $suf='</li>', $excerpt=true) {
        global $wpdb;
        $querystr = "SELECT $wpdb->posts.post_title,$wpdb->posts.post_date_gmt, $wpdb->posts.ID, $wpdb->posts.post_content FROM $wpdb->posts WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'post' ORDER BY $wpdb->posts.comment_count DESC LIMIT $num";
        $myposts = $wpdb->get_results($querystr, OBJECT);
        foreach($myposts as $post) {
                echo $pre;
                ?><div class="fpimg">

          <img src="<?php get_post_thumbnail($post->ID); ?>" />
        </div>
                <div class="fpost">
        <a href="<?php echo get_permalink($post->ID); ?>"><?php echo $post->post_title ?></a><br />
                <?php if (function_exists('time_since')) {echo time_since(abs(strtotime($post->post_date_gmt . " GMT")), time()) . " ago";} else {the_time('F jS, Y');} ?>
                </div>
                <?php echo $suf;
        }
}


function get_recent_posts($num) {
      $recent_posts = wp_get_recent_posts($num);
      foreach($recent_posts as $post){
          ?>
          <li><div class="fpimg"> <?php echo '<a href="' . get_permalink($post["ID"]) . '" title="Look '.$post["post_title"].'" >'; ?>
          <img src="<?php get_post_thumbnail($post["ID"]); ?>" />
          </div>
          <div class="fpost">
        <?php echo '<a href="' . get_permalink($post["ID"]) . '" title="Look '.$post["post_title"].'" >' .   $post["post_title"].'</a>  ';?>
                <br />
                <?php if (function_exists('time_since')) {echo time_since(abs(strtotime($post["post_date_gmt"] . " GMT")), time()) . " ago";} else {the_time('F jS, Y');} ?>
                </div>
                </li>
    <? }


         }
function time_since($older_date, $newer_date = false)
        {
        // array of time period chunks
        $chunks = array(
        array(60 * 60 * 24 * 365 , 'year'),
        array(60 * 60 * 24 * 30 , 'month'),
        array(60 * 60 * 24 * 7, 'week'),
        array(60 * 60 * 24 , 'day'),
        array(60 * 60 , 'hour'),
        array(60 , 'minute'),
        );

        // $newer_date will equal false if we want to know the time elapsed between a date and the current time
        // $newer_date will have a value if we want to work out time elapsed between two known dates
        $newer_date = ($newer_date == false) ? (time()+(60*60*get_settings("gmt_offset"))) : $newer_date;

        // difference in seconds
        $since = $newer_date - $older_date;

        // we only want to output two chunks of time here, eg:
        // x years, xx months
        // x days, xx hours
        // so there's only two bits of calculation below:

        // step one: the first chunk
        for ($i = 0, $j = count($chunks); $i < $j; $i++)
                {
                $seconds = $chunks[$i][0];
                $name = $chunks[$i][1];

                // finding the biggest chunk (if the chunk fits, break)
                if (($count = floor($since / $seconds)) != 0)
                        {
                        break;
                        }
                }

        // set output var
        $output = ($count == 1) ? '1 '.$name : "$count {$name}s";

        // step two: the second chunk
        if ($i + 1 < $j)
                {
                $seconds2 = $chunks[$i + 1][0];
                $name2 = $chunks[$i + 1][1];

                if (($count2 = floor(($since - ($seconds * $count)) / $seconds2)) != 0)
                        {
                        // add to output var
                        $output .= ($count2 == 1) ? ', 1 '.$name2 : ", $count2 {$name2}s";
                        }
                }

        return $output;
        }
function get_post_thumbnail($pid) {
$files = get_children('post_parent='.$pid.'&post_type=attachment&post_mime_type=image');
if($files) :
$keys = array_reverse(array_keys($files));
$j=0;
$num = $keys[$j];
$image=wp_get_attachment_image($num, 'large', false);
$imagepieces = explode('"', $image);
$imagepath = $imagepieces[1];
$thumb=wp_get_attachment_thumb_url($num);
print $thumb;
else:
echo  bloginfo('template_directory')."/images/smallimg.jpg";
endif;
}
function get_post_thumbnails() {
$files = get_children('post_parent='.get_the_ID().'&post_type=attachment&post_mime_type=image');
if($files) :
$keys = array_reverse(array_keys($files));
$j=0;
$num = $keys[$j];
$image=wp_get_attachment_image($num, 'large', false);
$imagepieces = explode('"', $image);
$imagepath = $imagepieces[1];
$thumb=wp_get_attachment_thumb_url($num);
print $thumb;
else:
echo  bloginfo('template_directory')."/images/smallimg.jpg";
endif;
}
?>
php nginx php5 php-fpm
  • 2 2 个回答
  • 12593 Views

2 个回答

  • Voted
  1. Best Answer
    Julie Pelletier
    2016-06-20T12:48:32+08:002016-06-20T12:48:32+08:00

    您的问题显然与函数<?末尾附近的短打开标签有关get_recent_posts()。

    将其更改为<?php,该问题将消失。

    下次遇到编程错误时,请参阅http://stackoverflow.com。

    • 1
  2. uberrebu
    2016-06-20T12:53:20+08:002016-06-20T12:53:20+08:00

    好的,这就是我所做的,错误消失了

    编辑了 php.ini 文件

    nano /etc/php5/fpm/php.ini

    并做了这个改变,基本上从关闭变成了开启

    ;short_open_tag = Off 
    short_open_tag = On
    

    取而代之的是,我想知道如何解决该错误

    谢谢

    更新:这仅适用于 PHP 5.5.9 但不适用于 PHP 7.0.4 所以仍然希望以更好的方式解决它

    • 0

相关问题

  • 用户特定的 Php.ini 当 php 作为模块运行时?

  • 使 php mail() 函数在 ubuntu-server 上工作的步骤是什么?

  • Web 服务器和数据库服务器位于完全不同的位置

  • PHP 作为 CGI 还是 Apache 模块?

  • 通过 VPN 连接什么是远程服务器 IP?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve