PHP code example of voceconnect / no-stampede-actions

1. Go to this page and download the library: Download voceconnect/no-stampede-actions library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

voceconnect / no-stampede-actions example snippets



	if( ! class_exists( 'NSA_Action' ) ) {
		


function long_request(){
	$val = wp_cache_get( 'long_request_key' );
	if( $val === false ){
		nsa_action('long_request')
			->action_callback( 'long_request_callback', array( 'http://example.com/long-running-request.php' ) )
			->background_only( false )
			->max_tries( 10 )
			->do_action( );

		$val = wp_cache_get( 'long_request_key' );
	}
	return $val;
}

function long_request_callback($url){
	$content = wp_remote_retrieve_body( wp_remote_get( $url, array( 'timeout' => 30 ) ) );
	wp_cache_set( 'long_request_key', $content );
	return $content;
}