为什么在我将 googlesnippets ld + json 添加到我的 php 页面时出现错误? 503 服务不可用

Why does it give an error when I add googlesnippets ld + json to my php page? 503 Service Unavaible

edit : 详细研究后发现,由于脚本不好导致即时密度过大时,cpu 逾期下降到 503。感谢大家的回复。


我的电子商务 php 索引页面脚本添加 google 片段 ld+json java 脚本运行一段时间后出现错误(503 服务不可用)。

我正在保存 php display_errors 我再次保存的 cPanel 上的勾号。工作正常。然后,过了一会儿,它突然报错 503。从页面中删除 java 脚本代码后,当我清除缓存时,它不再报错。

在我的函数文件中创建:

 function GoogleSnippetsWebsite($snippets) {
     $out ='<script type="application/ld+json">{'."\n";
     $out.='"@context":"https://schema.org",'."\n";
     $out.='"@type": "WebSite",'."\n"; 
     $out.='"url": "https://www.-----.com",'."\n";
     $out.='"name":"----.com",'."\n";
     $out.=' "inLanguage":"en-US",'."\n";  
     $out.=' "sameAs":['."\n";
     $out.=' "https://www.---.com/",'."\n";  
     $out.=' "https://www.---.com/" ],'."\n";
     $out.=' "potentialAction": {'."\n";
     $out.='"@type": "SearchAction",'."\n";
     $out.='"target": "https://www.----.com/search=&src={search_term_string}",'."\n";  
     $out.='"query-input": "required name=search_term_string"}}'."\n";  
     $out.='</script>'."\n";    
     return $out; 
}

我想显示我的 php 页面:

<head>  
    <?php echo GoogleSnippetsWebsite('website'); ?>
</head>

工作 5 分钟。在 503 服务不可用之后。

也许很简单,但我无法解决。我没有得到 google 搜索的结果。你有什么建议?谢谢。

503 服务不可用

当服务器资源太少无法执行您想要执行的请求时,HTTP 503(服务不可用)通常是一个错误。查看您的问题,这似乎也是这种情况,因为它在服务器 returns 此错误消息之前工作了几分钟。

确保您有足够的带宽和存储空间等可以使用。 一个解决方案是找一个没有这些限制的主机

您先使用 $deger,然后使用 $out,因此 $out 字符串没有第一行。

请注意,您没有首先启动 $out,这一定是 503 错误的来源。

为了更好的可读性,我建议避免在每一行使用$out.=,只需在开头使用一个点连接并删除末尾的每个分号(最后一个连接除外)。

function GoogleSnippetsWebsite($snippets) {
    $out ='<script type="application/ld+json">{'."\n"
        .'"@context":"https://schema.org",'."\n"
        .'"@type": "WebSite",'."\n";
        .'"url": "https://www.-----.com",'."\n"
        .'"name":"----.com",'."\n"
        .' "inLanguage":"en-US",'."\n"
        .' "sameAs":['."\n"
        .' "https://www.---.com/",'."\n"
        .' "https://www.---.com/" ],'."\n"
        .' "potentialAction": {'."\n"
        .'"@type": "SearchAction",'."\n"
        .'"target": "https://www.----.com/search=&src={search_term_string}",'."\n"
        .'"query-input": "required name=search_term_string"}}'."\n"
        .'</script>'."\n";

    return $out; 
}

我会说我个人使用 PHP_EOL 而不是 "\n" ;)