js

Sunday, February 11, 2024

Explain memory_get_usage() in php

 

memory_get_usage() is a PHP function used to retrieve the amount of memory, in bytes, that is currently being allocated to the PHP script during its execution. This function can be valuable for monitoring and optimizing memory usage within your PHP application.

Here's a brief explanation of the memory_get_usage() function:

php
int memory_get_usage(bool $real_usage = false)
  • Parameters:

    • $real_usage (optional): When set to true, the function returns the real system memory usage, which may be higher than the amount allocated to PHP. If set to false or omitted, it returns the memory usage within the PHP script.
  • Return Value:

    • The function returns the memory usage in bytes as an integer.

Here's a simple example:

php
<?php
// Start memory usage
$start_memory
= memory_get_usage();
// Allocate some memory

$data
= str_repeat('a', 1024 * 1024);
// Allocating 1 MB of memory
// Get current memory usage
$current_memory = memory_get_usage();
// Output memory usage

echo
"Memory usage before: " . $start_memory . " bytes\n";
echo "Memory usage after: " . $current_memory . " bytes\n";
echo
"Memory usage diff: " . ($current_memory - $start_memory) . " bytes\n";
?>

In this example, the memory_get_usage() function is used to measure the memory usage before and after allocating a block of memory with str_repeat. The difference between the two memory measurements represents the amount of memory used by the script during the allocation.

Keep in mind that the actual memory usage can be influenced by various factors, and interpreting the results may require consideration of PHP's memory management mechanisms. Additionally, it's worth noting that the memory_get_usage() function provides a snapshot of the memory usage at the moment it's called and may not represent the peak usage during the script's execution. For peak memory usage, you can use memory_get_peak_usage().

Question sample

Find the antonym of the given words.
1. PUERILE
A) Dirty
B) Mature
C) Naive
D) Impure

Answer:  

B) Mature

The word "PUERILE" is an adjective in English, and it refers to something that is childish, immature, or characteristic of a child. It describes things that are trivial, silly, or lacking in maturity. For example, if someone's behavior is described as puerile, it means that their actions or attitudes are reminiscent of a child and are considered immature or juvenile.

2. GLOAT
A) Regrat
B) Boast
C) Consider
D) Laugh

Answer:  

A) Regrat

to feel or express great pleasure or satisfaction because of your own success or good luck, or someone else's failure or bad luck:
gloat over/about She's continually gloating over/about her new job.
I know I shouldn't gloat, but it really serves him right.
gloat at His enemies were quick to gloat at his humiliation.
[ + speech ] "This is our fourth victory in a row," he gloated.

 

3. MYSTIFY
A) Persuade
B) Begile
C) Rain
D) Satisfy

Answer:

B) Begile

4. Find the incorrectly spelt word.
A) Inveigle
B) Carat
C) Taxydermy
D) Karat

Answer:

C) Taxydermy
The correct spelling is "Taxidermy." 

 

 

 

8. A person who walks in his sleep
A) Somnambulist
B) Acrobat
C) Philologist
D) Publican 

Answer:

A) Somnambulist

40. Find the odd number among the following numbers: 396, 462, 572, 427, 671, 264
A) 427
B) 396
c) 671
D) 572







 Q. To get the current memory usage which PHP function is used?
a) get_usage()
b) memory_get_usage()
c) get_peak_usage()
d) memory_get_peak_usage()

Answer:
memory_get_usage()

 

 

Test scrappe

This is for scrapping. 

Have a nice day
 
This is not for scrapping. Have a nice day
This is for scrapping second time. Have a nice day

Explain web scrapping

 

Web scraping is a technique used to extract information or data from websites. It involves automated gathering of data from the web by sending requests to web pages, retrieving the HTML content, and then parsing and extracting the desired information. Web scraping can be useful for various purposes such as data analysis, research, monitoring, and more.

Here is a step-by-step explanation of how web scraping typically works:

  1. Send a Request: The process begins with sending an HTTP request to the target website. This request is similar to the one your browser sends when you visit a website. It asks the server for the HTML content of the web page.

  2. Receive HTML Content: Once the server receives the request, it sends back the HTML content of the web page as a response. This HTML contains the structure and content of the page.

  3. Parse HTML: The next step is to parse the HTML content. Parsing involves breaking down the HTML into its individual elements (like tags, attributes, and text). This is usually done using tools like BeautifulSoup in Python or other similar libraries.

  4. Locate Data: With the parsed HTML, the scraper can locate and extract the specific data of interest. This involves identifying the HTML elements (tags, classes, IDs) that contain the desired information.

  5. Data Extraction: Once the relevant elements are identified, the scraper extracts the data from those elements. This could be text, images, links, or any other information embedded in the HTML.

  6. Data Storage/Analysis: The extracted data can then be stored in a structured format (like a CSV file, database, or JSON) for further analysis or used for various applications.

It's important to note that while web scraping can be a powerful tool for extracting data, it should be done responsibly and ethically. Always check a website's terms of service before scraping, and ensure that your scraping activities are in compliance with legal and ethical guidelines.

Web scraping is widely used in fields such as data science, market research, competitive analysis, and more. However, it's crucial to respect the terms and conditions of the websites you scrape and to avoid causing any harm or disruption to the target site.

Thursday, February 8, 2024

Defferences between bindParam() and bindValue() in php

 

In PHP, both bindParam() and bindValue() are methods used with PDO (PHP Data Objects) to bind parameters to a prepared statement for database queries. However, there are key differences between the two:

  1. Binding Values:

    • bindParam(): Binds a variable to a parameter. It allows for passing variables by reference, meaning that if the value of the variable changes after the bindParam() call, the bound parameter's value will also change.
    • bindValue(): Binds a value to a parameter. It does not allow passing variables by reference; it binds the parameter to the specific value at the time of the call.
  2. Data Type Binding:

    • bindParam(): Requires specifying the data type of the parameter as a separate parameter (e.g., PDO::PARAM_INT, PDO::PARAM_STR). It can be useful when dealing with parameters that might change type during execution.
    • bindValue(): Infers the data type of the parameter from the provided value. It automatically determines whether the value is an integer, string, boolean, or NULL.
  3. Ease of Use:

    • bindParam(): It can be more flexible when dealing with variables that might change during the execution of the script.
    • bindValue(): It is simpler to use when binding static values or when the value is not expected to change.
  4. Examples:

    php
    // Using bindParam
    $variable
    = 42;
    $stmt
    = $pdo->prepare("SELECT * FROM table WHERE column = :value");
    $stmt->bindParam(':value', $variable, PDO::PARAM_INT);
    $variable
    = 24; // This will affect the bound parameter
    // Using bindValue

    $value
    = 42;
    $stmt = $pdo->prepare("SELECT * FROM table WHERE column = :value");
    $stmt
    ->bindValue(':value', $value, PDO::PARAM_INT);
    $value = 24;
    // This won't affect the bound parameter

In summary, choose between bindParam() and bindValue() based on your specific use case. If you need the flexibility of binding variables by reference or dealing with changing data types, bindParam() might be more suitable. If you prefer simplicity and don't need the variable-binding reference behavior, bindValue() is often easier to use.

AHSEC| CLASS 11| GEOGRAPHY| SOLVED PAPER - 2015| H.S.1ST YEAR

  AHSEC| CLASS 11| GEOGRAPHY| SOLVED PAPER - 2015| H.S.1ST YEAR 2015 GEOGRAPHY SOLVED PAPER Full Marks: 70 Time: 3 hours The figures in the...