長いスクリプトがある場合は、各タスクの入力パラメーターの助けを借りてページ作業を分割します(その後、各ページはスレッドのように機能します)。つまり、ページに1つのlac product_keywords長いプロセスループがある場合、ループの代わりに1つのキーワードのロジックを作成し、このキーワードを渡しますmagic または cornjobpage.php から (次の例)
バックグラウンド ワーカーの場合は、この手法を試してみるべきだと思います。好きなだけページを呼び出すと、すべてのページが非同期として各ページの応答を待たずに一度に独立して実行されます。
cornjobpage.php //メインページ
<?php
post_async("http://localhost/projectname/testpage.php", "Keywordname=testValue");
//post_async("http://localhost/projectname/testpage.php", "Keywordname=testValue2");
//post_async("http://localhost/projectname/otherpage.php", "Keywordname=anyValue");
//call as many as pages you like all pages will run at once independently without waiting for each page response as asynchronous.
?>
<?php
/*
* Executes a PHP page asynchronously so the current page does not have to wait for it to finish running.
*
*/
function post_async($url,$params)
{
$post_string = $params;
$parts=parse_url($url);
$fp = fsockopen($parts['host'],
isset($parts['port'])?$parts['port']:80,
$errno, $errstr, 30);
$out = "GET ".$parts['path']."?$post_string"." HTTP/1.1\r\n";//you can use POST instead of GET if you like
$out.= "Host: ".$parts['host']."\r\n";
$out.= "Content-Type: application/x-www-form-urlencoded\r\n";
$out.= "Content-Length: ".strlen($post_string)."\r\n";
$out.= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
fclose($fp);
}
?>
testpage.php
<?
echo $_REQUEST["Keywordname"];//case1 Output > testValue
?>
PS: URL パラメータをループとして送信する場合は、次の回答に従ってください: https://stackoverflow.com/a/41225209/6295712