在我的 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 關注
- 109 瀏覽
添加回答
舉報
0/150
提交
取消