PluginProbe
Quill Forms | Conversational Multi Step Forms, Surveys & quizzes / trunk
Quill Forms | Conversational Multi Step Forms, Surveys & quizzes vtrunk
5.7.3 5.7.2 5.7.1 1.8.1 1.8.10 1.8.11 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 2.0.0 2.1.0 2.10.0 2.11.0 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 All 146 releases
quillforms / includes / class-utils.php

class-utils.php in Quill Forms | Conversational Multi Step Forms, Surveys & quizzes trunk, at includes/class-utils.php

98 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Utils class
4 *
5 * @since next.version
6 *
7 * @package QuillForms
8 */
9
10 namespace QuillForms;
11
12 /**
13 * Utils Class
14 */
15 final class Utils {
16
17 /**
18 * Get max execution time
19 *
20 * @return int
21 */
22 public static function get_max_execution_time() {
23 $max_execution_time = 30;
24
25 if ( function_exists( 'ini_get' ) ) {
26 $max_execution_time = ini_get( 'max_execution_time' );
27
28 if ( ! $max_execution_time ) {
29 $max_execution_time = 30;
30 }
31 }
32
33 // Decrease a little bit to avoid reaching the limit.
34 $max_execution_time = $max_execution_time * 0.75;
35 return apply_filters( 'quillforms_max_execution_time', $max_execution_time );
36 }
37
38 /**
39 * Is memory limit reached
40 *
41 * @return bool
42 */
43 public static function is_memory_limit_reached() {
44 $memory_limit = self::get_memory_limit();
45 $memory_usage = memory_get_usage( true );
46 $memory_limit = self::convert_to_bytes( $memory_limit );
47 $memory_limit = $memory_limit * 0.75;
48
49 return $memory_usage >= $memory_limit;
50 }
51
52 /**
53 * Get memory limit
54 *
55 * @return string
56 */
57 public static function get_memory_limit() {
58 $memory_limit = '128M';
59
60 if ( function_exists( 'ini_get' ) ) {
61 $memory_limit = ini_get( 'memory_limit' );
62
63 if ( ! $memory_limit ) {
64 $memory_limit = '128M';
65 }
66 }
67
68 return apply_filters( 'quillforms_memory_limit', $memory_limit );
69 }
70
71 /**
72 * Convert to bytes
73 *
74 * @param string $value
75 *
76 * @return int
77 */
78 public static function convert_to_bytes( $value ) {
79 $value = trim( $value );
80 $last = strtolower( $value[ strlen( $value ) - 1 ] );
81 $new_value = intval( $value );
82
83 switch ( $last ) {
84 case 'g':
85 $new_value *= GB_IN_BYTES;
86 break;
87 case 'm':
88 $new_value *= MB_IN_BYTES;
89 break;
90 case 'k':
91 $new_value *= KB_IN_BYTES;
92 break;
93 }
94
95 return $new_value;
96 }
97 }
98