<?php
function parse( $limiter = null ) {
/**
* Start parsing!
*/
$return_values = curl_multi_download( array(
"users/" . userid,
'projects',
'comments/?o=-submit_date&page_size=5',
'tasks/?deadline=5',
), urlpath );
/**
* End parsing!
*/
switch ( $limiter ) {
case 'index':
$return = array( 'projects' => $return_values['projects'],
'username' => $return_values['users/' . userid]['username'],
'calander_num' => '2',
'alerts_num' => '32',
'messages_num' => '123',
'7_days_tasks_due' => '10'
);
break;
case 'dashboard':
$return = array( 'username' => $return_values['users/' . userid]['username'],
'recent_comments' => $return_values['comments/?o=-submit_date&page_size=5'],
't_7_days' => day_counter($return_values['tasks/?deadline=5'], 7),
'projects' => $return_values['projects']
);
break;
default:
return null;
break;
}
return $return;
}
function day_counter($array, $index) {
$datearray = array();
foreach ($array['results'] as $key => &$value) {
array_push($datearray , $array['results'][$key]['deadline']);
}
$datearray = array_count_values($datearray);
for ($i = 0; $i < $index; $i++) {
if (isset($datearray[date('Y-m-d', strtotime('+'.$i.' day', time()))])) {
$return[$i] = $datearray[date('Y-m-d', strtotime('+'.$i.' day', time()))];
} else {
$return[$i] = 0;
}
}
return $return;
}
function curl_multi_download( array $urls, $urlpath, array $custom_options = array() )
{
// make sure the rolling window isn't greater than the # of urls
$rolling_window = 20;
$rolling_window = ( sizeof( $urls ) < $rolling_window ) ? sizeof( $urls ) : $rolling_window;
$master = curl_multi_init();
$curl_arr = array();
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_MAXREDIRS => 5,
) + $custom_options;
// start the first batch of requests
for ( $i = 0; $i < $rolling_window; $i++ )
{
$ch = curl_init();
$options[CURLOPT_URL] = $urlpath . $urls[$i];
curl_setopt_array( $ch, $options );
curl_multi_add_handle( $master, $ch );
}
$return_values = array();
do
{
while ( ( $execrun = curl_multi_exec( $master, $running ) ) == CURLM_CALL_MULTI_PERFORM );
if ( $execrun != CURLM_OK )
break;
// a request was just completed -- find out which one
while ( $done = curl_multi_info_read( $master ) )
{
$info = curl_getinfo( $done['handle'] );
// request successful. process output using the callback function.
$output = curl_multi_getcontent( $done['handle'] );
// call_user_func_array($callback, array($info, $output));
if ( $info['http_code'] == '200' ) {
//print_r(curl_getinfo($done['handle']));
//$return_values[curl_getinfo($done['handle'])['url']] = json_decode( $output, true );
$return_values[rtrim( substr( curl_getinfo($done['handle'])['url'], strlen ($urlpath) ), '/' )] = json_decode( $output, true );
}
// var_dump($return_values);
if ( isset( $urls[$i + 1] ) )
{
// start a new request (it's important to do this before removing the old one)
$ch = curl_init();
$options[CURLOPT_URL] = $urlpath . $urls[$i++]; // increment i
curl_setopt_array( $ch, $options );
curl_multi_add_handle( $master, $ch );
}
// remove the curl handle that just completed
curl_multi_remove_handle( $master, $done['handle'] );
}
} while ( $running );
curl_multi_close( $master );
return $return_values;
}
- Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.6
- Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
- Parse error: syntax error, unexpected '[' in /in/83ToL on line 103
Process exited with code 255. - Output for 5.0.0 - 5.0.5
- Parse error: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in /in/83ToL on line 64
Process exited with code 255. - Output for 4.4.2 - 4.4.9
- Parse error: syntax error, unexpected '&', expecting T_VARIABLE or '$' in /in/83ToL on line 47
Process exited with code 255. - Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
- Parse error: parse error, unexpected '&', expecting T_VARIABLE or '$' in /in/83ToL on line 47
Process exited with code 255. - Output for 4.3.2 - 4.3.4
- Parse error: parse error, expecting `T_VARIABLE' or `'$'' in /in/83ToL on line 47
Process exited with code 255.
preferences:
153.85 ms | 401 KiB | 217 Q