您可能应该看看站点的瞬变.
<?php
function so_73821350_get_transient_name() {
return 'so_73821350_transient_name'; // replace this with whatever you want
}
function so_73821350_upload_to_ipfs() {
// get the existing transient
//
// If the transient does not exist, does not have a value, or has expired,
// then the return value will be false.
$process_running = get_site_transient( so_73821350_get_transient_name() );
if ( $process_running ) {
// bail out in case the transient exists and has not expired
// this means the process is still running
return;
}
// set the transient to flag the process as started
// 60 is the time until expiration, in seconds
set_site_transient( so_73821350_get_transient_name(), 1, 60);
// Run the upload process here
upload_function();
// ...
// delete the transient to remove the flag and allow the process to run again
delete_site_transient( so_73821350_get_transient_name() );
}
add_action( 'upload_file', 'so_73821350_upload_to_ipfs' );
文档:
get_site_transient()个
set_site_transient()个
delete_site_transient()个