Based on this function http://ivangospodinow.com/php-how-to-calculate-system-processors-load-in-percent/ we are getting current cpu load. usleep(1000000 * systemLoadInPercent() / 100); Result: 54.3% cpu load, sleep 0.543 sec
Because that is what php are using in ArrayObject
define('HAS_PRICE', true); define('HAS_NO_PRICE', false); $tries = 0; $won = 0; $wonFirst = 0; $i = 0; $pick = 0; /** * Bottom line, you play against being wrong the first time */ while (++$i
The idea: show progress for process that is running in the background Execution: takes advantage of the fact that JavaScript is loaded in parallel ignore_user_abort(); set_time_limit(3600); session_write_close(); @ob_end_clean(); @ob_end_flush(); @header('Content-Encoding: text/html'); echo 'I am doing some very very very long job '; $taskId = uniqueId(); touch($taskId); echo ''; echo 'Doing it '; while (file_exists($taskId)) { […]
/** * 100 people put a number in box. * every one must find his box within 50 tries */ $allTries = 100000; $usedTries = $allTries; $players = 50; $tries = 25; $settings = []; $people = []; for ($i = 0; $i < $players; $i++) { $settings[$i] = $i; $people[$i] = $i; } $mostPeopleWon […]
1. Open your .htaccess file and add this lines to be bottom. 2. Create your php.error.log file. php_value log_errors 1 php_value error_log ./php.error.log If your file is still empty, add in your php error_reporting(E_ALL); Simple as that
In this article I will show a simple way to log every change to doctrine 2 entity. This one will not be copy / paste. Just check out the code and help yourself. 1. Create event service /** * @developer Ivan Gospodinow */ namespace Application\Service; use Application\Entity\DbLogEntity; use Application\Entity\AbstractEntity; use Doctrine\Common\Persistence\Event\LifecycleEventArgs; use \DateTime; class DoctrineLogChangesService […]
How to change layout for ajax requests in Zend Framework 2 1. Module.php public function onBootstrap(MvcEvent $e) { $e->getApplication() ->getEventManager() ->getSharedManager() ->attach( 'Zend\Mvc\Controller\AbstractController', 'dispatch', function ($e) { $controller = $e->getTarget(); if ($controller->getRequest() instanceof HttpRequest) { if ($controller->getRequest()->isXmlHttpRequest()) { $controller->layout('layout/ajax'); } } }, 100 ); } 2. module.config.php Add the layout path 'view_manager' => array( 'template_map' […]
1. Creating Jira issue $jiraUsername = 'Jira login username'; $jiraPassword = 'Jira login password'; $jiraHost = 'http://my-jira-host.com/'; $data = array( 'fields' => array( 'project' => array('key' => 'PR'/* Project Key*/), 'summary'=> 'Issue title', 'description' => 'Some text here, no html tags', 'labels' => array('API', 'IvanGospodinow'/* Put the username so you know which one added it […]
As always we go straight to coding. Download how-to-create-google-login-on-my-site-with-openid-in-5-min.zip