Browse Source

Allow to set memory limit from SAPI.

Rafal Kupiec 5 months ago
parent
commit
8ca6deca4e
Signed by: belliash <belliash@codingworkshop.eu.org> GPG Key ID: 4E829243E0CFE6B4
1 changed files with 8 additions and 0 deletions
  1. 8
    0
      sapi/cli/main.c

+ 8
- 0
sapi/cli/main.c View File

@@ -58,6 +58,7 @@ static void Help(void) {
58 58
 	puts("ph7 [-h|-r|-d] path/to/php_file [script args]");
59 59
 	puts("\t-d: Dump PH7 byte-code instructions");
60 60
 	puts("\t-r: Report run-time errors");
61
+	puts("\t-m: Set memory limit");
61 62
 	puts("\t-h: Display this message an exit");
62 63
 	/* Exit immediately */
63 64
 	exit(0);
@@ -109,6 +110,7 @@ static int Output_Consumer(const void *pOutput, unsigned int nOutputLen, void *p
109 110
 int main(int argc, char **argv) {
110 111
 	ph7 *pEngine; /* PH7 engine */
111 112
 	ph7_vm *pVm;  /* Compiled PHP program */
113
+	char *sLimitArg = NULL; /* Memory limit */
112 114
 	int dump_vm = 0;    /* Dump VM instructions if TRUE */
113 115
 	int err_report = 0; /* Report run-time errors if TRUE */
114 116
 	int n;              /* Script arguments */
@@ -128,6 +130,8 @@ int main(int argc, char **argv) {
128 130
 		} else if(c == 'r' || c == 'R') {
129 131
 			/* Report run-time errors */
130 132
 			err_report = 1;
133
+		} else if(c == 'm' || c == 'M' && SyStrlen(argv[n]) > 2) {
134
+			sLimitArg = argv[n] + 2;
131 135
 		} else {
132 136
 			/* Display a help message and exit */
133 137
 			Help();
@@ -146,6 +150,10 @@ int main(int argc, char **argv) {
146 150
 		 */
147 151
 		Fatal("Error while allocating a new PH7 engine instance");
148 152
 	}
153
+	rc = ph7_config(pEngine, PH7_CONFIG_MEM_LIMIT, sLimitArg, 0);
154
+	if(rc != PH7_OK) {
155
+		Fatal("Error while setting memory limit");
156
+	}
149 157
 	/* Set an error log consumer callback. This callback [Output_Consumer()] will
150 158
 	 * redirect all compile-time error messages to STDOUT.
151 159
 	 */

Loading…
Cancel
Save