在我的 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”脚本运行良好!
FFIVE