Tech Tip: PHP Parameter Size
PRODUCT: 4D | VERSION: 12.3 | PLATFORM: Mac & Win
Published On: November 9, 2011
When using PHP Execute the size of parameters passed must not exceed 64 KB. This can be a problem when using large amounts of text. One possilbe way to avoid this size limitation is to use a text file with the php command fopen in your script.
The following 4D code uses the PHP command ucwords to capitolize the first letter of every word in the $text variable.
However this will not work if the $text variable is larger than 64 KB in size.
The following 4D code combined with the PHP script utlizes 4Ds document commands to write and read a file that the PHP script will use to perform the same function as the first snippet of 4D code.
Please note: This 4D code uses the Get 4D Folder command, you can use any file path that you choose. The documents do not need to be in the Resources Folder.
textChangeFile.php
The following 4D code uses the PHP command ucwords to capitolize the first letter of every word in the $text variable.
C_TEXT($text;$result) $text:="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut at neque libero. " $text:=$text+"Phasellus eget urna sit amet elit laoreet sagittis " PHP Execute("";"ucwords";$result;$text) $text:=$result |
However this will not work if the $text variable is larger than 64 KB in size.
The following 4D code combined with the PHP script utlizes 4Ds document commands to write and read a file that the PHP script will use to perform the same function as the first snippet of 4D code.
Please note: This 4D code uses the Get 4D Folder command, you can use any file path that you choose. The documents do not need to be in the Resources Folder.
C_TEXT($text;$accumulate;$newText) C_BOOLEAN($phpSuccess;$result) $phpPath:=Get 4D Folder(Current Resources Folder)+"textChangeFile.php" $docPath:=Get 4D Folder(Current Resources Folder)+"temp.txt" $docRef:=Create Document($docPath) $text:="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut at neque libero. " $text:=$text+"Phasellus eget urna sit amet elit laoreet sagittis " $text:=$text*20000 SEND PACKET($docRef;$text) CLOSE DOCUMENT($docRef) $phpSuccess:=PHP Execute($phpPath;"foo";$result;"temp.txt") If ($phpSuccess & $result) $docRef:=Open Document($docPath) While (OK=1) RECEIVE PACKET($docRef;$newText;Char(Line Feed)) $accumulate:=$accumulate+$newText End while CLOSE DOCUMENT($docRef) $text:=$accumulate Else // PHP execute failed Alert("PHP Failed") End if |
textChangeFile.php
function foo ($fileName) { $handle = fopen($fileName,"r+"); if ($handle){ $tempString = fgets($handle); $tempString = ucwords($tempString); $handle = fopen($fileName,"w"); $check = fwrite($handle, $tempString); fclose($handle); if ($check>0){ return true; } else{ return false; } } } ?> |