TrueMember
Members-
Posts
25 -
Joined
-
Last visited
Everything posted by TrueMember
-
Fatal error: Allowed memory size of bytes exhausted
TrueMember replied to TrueMember's topic in PHP Coding Help
Thank you, that's it!😀 -
Fatal error: Allowed memory size of bytes exhausted
TrueMember replied to TrueMember's topic in PHP Coding Help
Any tips? I -
Fatal error: Allowed memory size of bytes exhausted
TrueMember replied to TrueMember's topic in PHP Coding Help
Yes, you can see the proof in the first post. I don't understand why. To try i added the code to controller and it happens again.. $url = "https://www.php.net"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, []); $response = curl_exec($ch); $dom = HtmlDomParser::str_get_html($response); echo '<pre>'; print_r($dom->find(".title")); echo '</pre>'; $dom->clear(); unset($dom); die(); -
Hi again, I did a simple request and i get right response from curl_exec($ch); but when i call the static method str_get_html my result is always the same. I tried increase the memory memory_limit=2048M but the result is the same. Proof of memory limit: Memory Limit I also tried ->clear(); unset(); but doesn't work. I'm using the following library: kub-at/php-simple-html-dom-parser My code: $url = "https://www.php.net"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, []); $this->callback = HtmlDomParser::str_get_html(curl_exec($ch)); .... Any tips? I can use regular expression, but will be my last choice. Thank you!
-
Thank you all. Problem solved adding this content to composer: "classmap": ["app/libraries", "app/controllers", "app/models"] For future troubles about this, i leave here a good tutorial about a simple MVC. (1/5 videos)
-
This is what i do in bootstrap.php but only for content inside libraries folder. I should do the same for controllers? Do you have any example?
-
I know that, but my ideia is change to work with version with error. But i don't have any ideia to do it.
-
I'm using this struture to run my application, everything works fine, but i don't like how the controllers are called. If i load the model in construct it will work great again, but i think that is unnecessary. You can see two pieces of code about controller "Post.php", the last one, works great. If i try this: (Posts.php) namespace app\controllers; use app\libraries\Controller; use app\models\User; class Posts extends Controller { public function index():void { //Get posts $user = new User(); $posts = $user->posts(); $data = [ 'posts' => $posts ]; $this->view('posts/index', $data); } } I will get an error: Structure: bootstrap.php //include all files from libraries require_once __DIR__ . "/../vendor/autoload.php"; index.php use app\libraries\Core; require_once '../app/bootstrap.php'; //Init Core Library $init = new Core(); core.php public function __construct(){ $url = $this->getUrl(); //Look in controllers for first value if(file_exists(dirname(__FILE__, 2) . '/controllers/' . ucwords($url[0]) . '.php')){ //if exists, set as controller $this->currentController = ucwords($url[0]); //Unset 0 index unset($url[0]); } //Require the controller require_once dirname(__FILE__, 2) . '/controllers/' . $this->currentController . '.php'; //instantiate controller class $class = 'app\\controllers\\' . $this->currentController; $this->currentController = new $class; //check for second part of url if(isset($url[1])){ //Check to see if method exists in controller if(method_exists($this->currentController, $url[1])){ $this->currentMethod = $url[1]; //Unset 1 index unset($url[1]); } } //Get params $this->params = $url ? array_values($url) : []; //Call a callback with array of params call_user_func_array([$this->currentController, $this->currentMethod], $this->params); } Posts.php class Posts extends Controller { public function __construct() { $this->userModel = $this->model('User'); $this->postModel = $this->model('Post'); } public function index():void { //Get posts $posts = $this->userModel->posts(); $data = [ 'posts' => $posts ]; $this->view('posts/index', $data); } } Controller.php abstract class Controller { /** * Load model * @param $model * @return mixed */ public function model($model) { //Require model file require_once '../app/models/' . $model . ".php"; //instantiate model $class = 'app\models\\' . $model; return new $class(); }
-
::1 is the IP address of the client. Maybe what you want is: $_SERVER['SERVER_ADDR']
-
I don't know what you want to do, you need be more specific. Nobody will work to you, if you want to learn, try by yourself and ask your doubts.
-
Enable errors and check what's wrong. Print the query and execute directly on database. <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); $Title = $_POST['title']; $Price = $_POST['price']; $Author = $_POST['author']; $con = mysqli_connect('localhost', 'root') or die("not connected"); mysqli_select_db($con, 'BRM_DB'); if (!$con) { echo "ERROR: " . mysqli_connect_errno() . PHP_EOL; echo "ERROR: " . mysqli_connect_error() . PHP_EOL; die; } $query = "INSERT INTO book(title,Price,Author)values('$Title',$Price,'$Author')"; $result = mysqli_query($con, $query); mysqli_close($con); ?> <!DOCTYPE html> <html> <head> <title>Insertion</title> </head> <body> <h1>Book Record Management</h1> <p> <?php if ($result == 1) { echo ("Record inserted"); } else { echo ("insertion failed"); } ?> </p> <a href="insertform.php">click here</a> </body> </html>
-
U should use $_POST, try the below code: $var_username = $_POST['username']; $message = '<p>Hello</p>' . $var_username . '<p>Please click the following link to activate your account : <a href="' . $var_username . $activate_link . '">' . $activate_link . '</a></p>';
-
I think this is the result intended. HTML: <label for="firstname"> <i class="fas fa-user"></i> </label> <input type="text" name="firstname" placeholder="Firstname" id="firstname" required > <input type="text" name="surname" placeholder="Surname" id="surname" required > <br> <label id="result"></label> JQUERY: $(document).ready( function() { $("#firstname, #surname").keyup( function() { var firstname = $("#firstname").val($("#firstname").val().toUpperCase()); var surname = $("#surname").val($("#surname").val().toUpperCase()); $("#result").html(firstname.val() + " " + surname.val()); }); });
-
Try this: $fields = array( 'username' => urlencode('xxx'), 'password' => urlencode('xxx'), 'B1' => 'Submit' );
-
issue with ODBC connecting to MSSQL PHP?
TrueMember replied to killmasta93's topic in Microsoft SQL - MSSQL
Did you tried telnet the IP PORT? Like: telnet 192.168.1.152 1433 -
You should add the width to the buttons, the content length is different, so the width when no specified will be different too.
-
Unable to print out array from a PHP function
TrueMember replied to Robinson's topic in PHP Coding Help
You can remove " of this two lines: $years_arr = array($year); $residue_arr = array($remainingMonth); -
First of all, you can check if value was updated directly on your database. Second, if you are using PHP version >= 5.5.0, the mysql_query was deprecated, you should use MySQLi or PDO_MySQL. To find errors more easly i advice enable this (add to top of file): ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); PS: If you want use short tags like <? $count=0; ?> you should enable short_open_tag=On in your php.ini file.
-
Infinite loop is a good option? I don't think so, maybe i'm wrong. Can i check inside loop if i have new rows in database? If yes, keep going the job, else, i will leave the cicly and change something to 0 (this means, the script not running).
-
Yes, actualy the results shows imediatly, but, i have many problem with many requests at same time, because, as i said before, the server is very weak and old (can't be changed). The server blocks and need be restarted some times a day. So, I thought in that solution, each time every user click in button, the content go to the queue and can be executed individually. Answering to your question, while the task are running in background the user can continue doing her job and when the job is completed, will sent an email. while (true){ $pendingRequests = loadPendingImportRequests(); foreach ($pendingRequests as $request){ processImportRequest($request); } sleep(1); //Avoid eating up CPU when idle. } In you example, you have an infinite loop, it will never stop. Thank you!
-
Of course. Second point call an independent script (generate.php). The script include a while loop (point 3) and inside the "while" will read each line (with executed=0), with values stored in database i will call a form (via curl) and i go to save the html code returned (each iteration can take 40seconds). Do you understood?
-
Ok, but i have another question to you. Script is running and i write something in one folder but if someone click in button when the script is running? I'm inside the while loop, i will get the new rows added with executed=0? I don't like this option, because i have another jobs running and the server is very weak.
-
How do you think I can do that? I don't got your point. Why? I need lunch to execute the task immediately. I can shedule a job, but i need it run at every 5 minutos to check any entry to be executed. (i have another jobs and shouldn't not be a good solution) Thanks all
-
Hi folks, I'm trying do a system like a queue, but doesn't work like i expected. OS: Windows (IIS) PHP: 5.2 So, let me tell you, what i'm doing. 1º Click in one button and insert the entry into database $stmt = odbc_prepare($conn, 'INSERT INTO queue (ask_date, run_date, executed, user_id) VALUES (GETDATE(), NULL, 0, ?)'); 2º After that i will run a script to check values executed = 0 $handle = new COM('WScript.Shell'); $handle->Run("php generate.php", 0, false); 3º Check values executed = 0 and update de column executed to 1 (generate.php) $sql = "SELECT * FROM queue WHERE executed=0;"; $rsQueue = odbc_exec($conn, $sql); while (odbc_fetch_row($rsQueue )) { //code here } My problem is, when i click in button it will open always new process (php.exe). (2 clicks - 2 processes; 3 clicks - 3 processes; etc..) My ideia is, first button click execute the script (2º) but the other times if script is running, only add the content to queue table to be executed in current process. Someone have any ideia? Thank you!