在我的 php 脚本中,我通过shell_exec().(第二个脚本仅在 shell 中执行时才有效,我不知道为什么,但这在这里不重要。)这是调用另一个的主脚本: $result = shell_exec( 'php /html/wp-content/plugins/neuhof/includes/sync/load_products.php' ); $data = json_decode($result, true); foreach($data as $product) { if($product['ID'] !== NULL) { $wc_product = wc_get_product( $product['ID'] ); ?> <tr id="<?php echo $product['Xhartid']; ?>"> <td class="title column-title has-row-actions column-primary page-title"><strong><?php echo $wc_product->get_name(); ?></strong> <div class="row-actions">ID: <?php echo $product['ID']; ?> | <span class="view"> <a href="<?php echo get_permalink( $product['ID'] ); ?>" target="_blank"> Anschauen </a> </span></div> </td> <td><?php echo $product['operation']; ?></td> <td class="state">Warten auf WP-Cron...</td> </tr> <?php } else { ?> <tr id="<?php echo $product['Xhartid']; ?>"> <td class="title column-title has-row-actions column-primary page-title"><strong><?php echo $product['Xhartbez']; ?></strong> <div class="row-actions">Noch keine ID vergeben</div> </td> <td><?php echo $product['operation']; ?></td> <td class="state">Warten auf WP-Cron...</td> </tr> <?php } }脚本返回NULL,即使我尝试exec()得到错误,它们也是NULL.我不知道为什么这不起作用,因为shell_exec('ls')简单的“hello world”脚本运行良好!
1 回答

FFIVE
TA贡献1797条经验 获得超6个赞
(第二个脚本仅在 shell 中执行时才有效,我不知道为什么,但这在这里无关紧要。)
这可能是因为您提到的第二个脚本的 MSSQL 连接在您的 webserver 环境/webserver 使用的 php 配置中被阻止。
当您从 shell 运行第二个脚本时,它可能工作正常,因为它在不同的环境中工作。但是,当您在由您的网络服务器运行的 php 脚本中使用 shell_exec 运行第二个脚本时,它会使用被阻止的相同网络服务器环境启动。
因此,如果您尝试使用 shell_exec 作为“hack”来省略您的网络服务器环境中的限制,那么它将无法正常工作。
您应该联系您的服务器管理员来解决此问题。
- 1 回答
- 0 关注
- 110 浏览
添加回答
举报
0/150
提交
取消